Skip to content

Unify pyAnalyzeLaurel error classification#1131

Open
julesmt wants to merge 3 commits into
strata-org:mainfrom
julesmt:julesmt/feature/unify-pipeline-diagnostics
Open

Unify pyAnalyzeLaurel error classification#1131
julesmt wants to merge 3 commits into
strata-org:mainfrom
julesmt:julesmt/feature/unify-pipeline-diagnostics

Conversation

@julesmt
Copy link
Copy Markdown
Member

@julesmt julesmt commented May 6, 2026

The two pipeline stages (Python→Laurel, Laurel→Core) each had their own error-handling block, and the Laurel→Core one misreported user-facing errors as internal. Now both stages throw List DiagnosticModel and route through a single classifier that maps DiagnosticType to exit category. Preserves existing user_errors.txt and DETAIL formatting.

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

The two pipeline stages (Python→Laurel, Laurel→Core) each had their own
error-handling block, and the Laurel→Core one misreported user-facing
errors as internal. Now both stages throw List DiagnosticModel and
route through a single classifier that maps DiagnosticType to exit
category. Preserves existing user_errors.txt and DETAIL formatting.
@julesmt
Copy link
Copy Markdown
Member Author

julesmt commented May 6, 2026

@tautschnig Then I can use that to solve your suggestions in PR #1118

Satisfies lake lint's requirement that every Strata module be
transitively imported from the library root.
Copy link
Copy Markdown
Contributor

@MikaelMayer MikaelMayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Clean unification — the single classifier approach is a good simplification and the new test demonstrates the Laurel→Core user-error path that was previously misreported. A few items below.

/-- Errors from the pyAnalyzeLaurel pipeline: a batch of diagnostics.

Each entry carries a `DiagnosticType` (UserError, NotYetImplemented, StrataBug,
or Warning) so the caller can classify the batch into a single exit category
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 This docstring references "the prior three-case PipelineError inductive" — comments should be stateless and not reference previous versions of the code. Consider rephrasing to describe what this type is without referencing what it replaced.


/-- Helper: create a known-limitation diagnostic (intentionally unsupported). -/
public def mkKnownLimitationDiagnostic (msg : String) : DiagnosticModel :=
{ fileRange := FileRange.unknown, message := msg, type := .NotYetImplemented }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 mkKnownLimitationDiagnostic and mkInternalDiagnostic duplicate DiagnosticModel.fromMessage (defined in FileRange.lean) — they're equivalent to DiagnosticModel.fromMessage msg (type := .NotYetImplemented) and DiagnosticModel.fromMessage msg (type := .StrataBug) respectively. mkUserCodeDiagnostic adds the file/range so it has a reason to exist, but the other two could be inlined or replaced by the existing helper.

Comment thread StrataMain.lean Outdated

/-- Classify diagnostics and exit with the matching `pyAnalyzeLaurel` category.
`prefixMsg` is prepended to internal-error and known-limitation details;
user-error details use the diagnostic's own message + line/column only. -/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Docstring says "prefixMsg is prepended to internal-error and known-limitation details" but it's only used in the internalError branch. The knownLimitation branch uses d.message directly.

Comment thread StrataMain.lean Outdated
match userDiags.head? with
| none => pure ()
| some d =>
let filePath := match d.fileRange.file with | .file p => p
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 let filePath := match d.fileRange.file with | .file p => p — this is fine today since Uri has a single constructor, but if Uri ever gains another case (e.g., a URI scheme), this will silently break. A destructuring let .file filePath := d.fileRange.file would make the intent clearer and produce a compile error if Uri grows.

@julesmt julesmt force-pushed the julesmt/feature/unify-pipeline-diagnostics branch from d7f41b0 to 88245df Compare May 8, 2026 19:07
- PySpecPipeline: trim PipelineError/mkUserCodeDiagnostic docstrings;
  drop mkKnownLimitationDiagnostic / mkInternalDiagnostic (duplicated
  DiagnosticModel.fromMessage) and inline call sites via a local
  internalErr closure.
- StrataMain: tighten classifyDiagnosticsAndExit docstring (prefixMsg
  only prefixes internal-error details), fold the two duplicate
  filter/head? blocks into a firstOf helper, flatten emitUserErrorsFile
  with an early-return and destructuring `let .file filePath := …` so
  a future Uri case fails to compile.
@julesmt
Copy link
Copy Markdown
Member Author

julesmt commented May 8, 2026

@MikaelMayer thanks for your review. I tried to apply your suggestions :).

Copy link
Copy Markdown
Contributor

@MikaelMayer MikaelMayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 LGTM — all comments addressed.

@julesmt
Copy link
Copy Markdown
Member Author

julesmt commented May 8, 2026

@tautschnig could you be my second reviewer for merge, like that I can rewrite the other PR this afternoon

@joehendrix
Copy link
Copy Markdown
Contributor

This conflicts with #1093. I think unifying the concepts is good, but Laurel to core failures should be treated as internal errors. We should stop generating invalid laurel rather than rely on it to catch bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants