Skip to content

Commit

Permalink
[WebConsole] fix inconsistent order and warning status of Rust errors
Browse files Browse the repository at this point in the history
Signed-off-by: Karakatiza666 <bulakh.96@gmail.com>
  • Loading branch information
Karakatiza666 committed Oct 14, 2024
1 parent d59c6a1 commit 9e7aa02
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import InteractionsPanel from '$lib/components/pipelines/editor/InteractionsPanel.svelte'
import DeploymentStatus from '$lib/components/pipelines/list/DeploymentStatus.svelte'
import PipelineActions from '$lib/components/pipelines/list/Actions.svelte'
import { extractProgramErrors, programErrorReport } from '$lib/compositions/health/systemErrors'
import {
extractProgramErrors,
programErrorReport,
programErrorsPerFile
} from '$lib/compositions/health/systemErrors'
import { extractErrorMarkers, felderaCompilerMarkerSource } from '$lib/functions/pipelines/monaco'
import {
postPipelineAction,
Expand Down Expand Up @@ -50,10 +54,12 @@
}
const programErrors = $derived(
extractProgramErrors(programErrorReport(pipeline.current))({
name: pipeline.current.name,
status: pipeline.current.programStatus
})
programErrorsPerFile(
extractProgramErrors(programErrorReport(pipeline.current))({
name: pipeline.current.name,
status: pipeline.current.programStatus
})
)
)
let metrics = useAggregatePipelineStats(pipeline, 1000, 61000)
Expand Down
10 changes: 4 additions & 6 deletions web-console/src/lib/compositions/health/systemErrors.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import {
} from './systemErrors'

export const listPipelineErrors = (pipeline: ExtendedPipeline) => {
let programErrors = Object.values(
extractProgramErrors(() => pipeline)({
name: pipeline.name,
status: pipeline.programStatus
})
).flat(1)
let programErrors = extractProgramErrors(() => pipeline)({
name: pipeline.name,
status: pipeline.programStatus
})
let pipelineErrors = extractPipelineErrors(pipeline)
return {
programErrors,
Expand Down
108 changes: 58 additions & 50 deletions web-console/src/lib/compositions/health/systemErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,55 +108,59 @@ export const extractInternalCompilationError = <Report>(
}
}

export const extractRustCompilerError =
<Report>(
pipelineName: string,
source: string,
getReport: (pipelineName: string, message: string) => Report
) =>
(stderr: string): SystemError<any, Report> => {
const warning = /^warning:/.test(stderr)

const matchFileError = (fileName: string, fileRegex: RegExp, lineOffset: number) => {
const match = stderr.match(fileRegex)
if (!match) {
return undefined
}
const startLineNumber = parseInt(match[1]) + lineOffset
const startColumn = parseInt(match[2])
return {
name: `Error compiling ${pipelineName}`,
message: stderr, // 'Program compilation error. See details below:\n' + stderr
cause: {
entityName: pipelineName,
tag: 'programError',
source:
source +
`#${fileName}:` +
startLineNumber +
(startColumn > 0 ? ':' + startColumn.toString() : ''),
report: getReport(pipelineName, stderr),
body: {
startLineNumber: startLineNumber,
endLineNumber: startLineNumber,
startColumn: startColumn,
endColumn: startColumn + 10,
message: stderr
},
warning
}
export const extractRustCompilerError = <Report>(
pipelineName: string,
source: string,
getReport: (pipelineName: string, message: string) => Report
) => {
const matchFileError = (
stderr: string,
warning: boolean,
fileName: string,
fileRegex: RegExp,
lineOffset: number
) => {
const match = stderr.match(fileRegex)
if (!match) {
return undefined
}
const startLineNumber = parseInt(match[1]) + lineOffset
const startColumn = parseInt(match[2])
return {
name: `Error compiling ${pipelineName}`,
message: stderr, // 'Program compilation error. See details below:\n' + stderr
cause: {
entityName: pipelineName,
tag: 'programError',
source:
source +
`#${fileName}:` +
startLineNumber +
(startColumn > 0 ? ':' + startColumn.toString() : ''),
report: getReport(pipelineName, stderr),
body: {
startLineNumber: startLineNumber,
endLineNumber: startLineNumber,
startColumn: startColumn,
endColumn: startColumn + 10,
message: stderr
},
warning
}
}
}
return (stderr: string): SystemError<any, Report> => {
const warning = /^warning:/.test(stderr)
let err: SystemError<any, Report> | undefined
err = matchFileError('udf.toml', /\/Cargo\.toml:(\d+):(\d+)/, -10)
err = matchFileError(stderr, warning, 'udf.toml', /\/Cargo\.toml:(\d+):(\d+)/, -10)
if (err) {
return err
}
err = matchFileError('udf.rs', /\/udf\.rs:(\d+):(\d+)/, 0)
err = matchFileError(stderr, warning, 'udf.rs', /\/udf\.rs:(\d+):(\d+)/, 0)
if (err) {
return err
}
err = matchFileError('stubs.rs', /\/stubs\.rs:(\d+):(\d+)/, 0)
err = matchFileError(stderr, warning, 'stubs.rs', /\/stubs\.rs:(\d+):(\d+)/, 0)
if (err) {
return err
}
Expand All @@ -169,10 +173,12 @@ export const extractRustCompilerError =
tag: 'unrecognizedProgramError',
source,
report: getReport(pipelineName, stderr),
body: stderr
body: stderr,
warning
}
}
}
}

/**
* @returns Errors associated with source files
Expand All @@ -192,8 +198,7 @@ export const extractProgramErrors =
const result = match(pipeline.status)
.returnType<SystemError<any, Report>[]>()
.with({ RustError: P.any }, (e) => {
const rustCompilerErrorRegex =
/((warning:|^error:|error\[[\w]+\]:)[\s\S]+?)\n(\n|(?=( +Compiling|warning:|error:|error\[[\w]+\]:)))/gm
const rustCompilerErrorRegex = /^((warning:(?! `)|error(\[[\w]+\])?:)([\s\S])+?)\n\n/gm
const rustCompilerMessages: string[] =
Array.from(e.RustError.matchAll(rustCompilerErrorRegex)).map((match) => match[1]) ?? []
const rustCompilerErrors = [
Expand Down Expand Up @@ -245,15 +250,18 @@ export const extractProgramErrors =
}))
)
.otherwise(() => [])
return Object.fromEntries(
groupBy(
result,
(item) =>
item.cause.source.match(new RegExp(`#(${pipelineFileNameRegex})`))?.[1] ?? 'program.sql'
)
)
return result
}

export const programErrorsPerFile = <Report>(errors: SystemError<any, Report>[]) =>
Object.fromEntries(
groupBy(
errors,
(item) =>
item.cause.source.match(new RegExp(`#(${pipelineFileNameRegex})`))?.[1] ?? 'program.sql'
)
)

export const pipelineFileNameRegex = '[\\w-_\\.]+'

export const extractPipelineXgressErrors = ({
Expand Down

0 comments on commit 9e7aa02

Please sign in to comment.