Skip to content

feat: export compiler error types for errors.As classification - #216

Merged
Azorlogh merged 2 commits into
mainfrom
claude/export-compiler-errors
Oct 9, 2026
Merged

Azorlogh merged 2 commits into
mainfrom
claude/export-compiler-errors

Conversation

@Azorlogh

@Azorlogh Azorlogh commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Refs EN-2833.

Ledger compiles committed scripts during Raft apply and must record compile and var-binding failures as structured audit facts. Today Compile flattens its typed errors with fmt.Errorf("%v", …), and VarsEncoder.Encode builds var failures as plain strings, so a host can only match on text.

Changes

  1. Compile returns the compiler's typed error as is (CompilerError now embeds error). Messages are unchanged.
  2. VarsEncoder.Encode returns MissingVariable{Name} and InvalidVariableValue{Name, Type, Raw, Cause} (Unwrap yields Cause). Messages are unchanged.
  3. numscript.go aliases them with a Compiler prefix (the interpreter already exports TypeError, CannotCastToString, ExperimentalFeature, InvalidFeature), grouped as:
    • caused by the script: CompilerTypeError, CompilerInvalidUncappedSource, CompilerDuplicateRemaining, CompilerInvalidMetaPosition, CompilerCannotCastToString, CompilerCannotStoreScopedAccountInMeta, CompilerExperimentalFeature, CompilerInvalidFeature;
    • unsupported by the compiler yet: CompilerFeatureNotImplemented (only scaling today);
    • numscript defects: CompilerUnboundVar (the type checker rejects unbound variables first), CompilerInvalidScopedAccountPosition, CompilerUnsupportedNode;
    • caused by the vars: CompilerMissingVariable, CompilerInvalidVariableValue;
    • plus the CompilerError interface.
  4. CompilerTypeError.Kind comes from the type checker, so its kinds are exported too: TypecheckErrorKind, TypecheckTypeMismatch, TypecheckUnboundVariable, TypecheckInvalidType, TypecheckBadArity, TypecheckUnknownFunction, TypecheckDuplicateVariable.
  5. Same field-stability contract as feat: export interpreter error types for errors.As classification #215 (merged).
  6. Tests in errors_test.go: every non-defect type (and every type-checker kind) is reached through CompileWithFeatureFlags or VarsEncoder.Encode, and errors.As plus key fields are checked.

Not covered: errors from ir.Typecheck / ir.Assemble after lowering. They mean the compiler emitted invalid IR (a numscript defect) and stay untyped.

@NumaryBot NumaryBot added risk: medium NumaryBot classified this pull request as medium risk. bot-reviewed NumaryBot completed its review workflow for the current head. review-inconclusive labels Oct 9, 2026
@ascandone
ascandone self-requested a review October 9, 2026 13:39
ascandone
ascandone previously approved these changes Oct 9, 2026
@NumaryBot NumaryBot removed risk: medium NumaryBot classified this pull request as medium risk. bot-reviewed NumaryBot completed its review workflow for the current head. review-inconclusive labels Oct 9, 2026
Comment thread numscript.go
@NumaryBot NumaryBot added risk: medium NumaryBot classified this pull request as medium risk. bot-reviewed NumaryBot completed its review workflow for the current head. review-inconclusive labels Oct 9, 2026
Base automatically changed from claude/export-interpreter-errors-b67bbd to main October 9, 2026 13:49
@Azorlogh
Azorlogh dismissed ascandone’s stale review October 9, 2026 13:49

The base branch was changed.

Compile flattened its typed errors into plain text, and VarsEncoder.Encode
built var-binding failures as strings, so a host could only tell compile
and var failures apart by string matching. Return compiler errors as is,
give var-binding failures typed errors (MissingVariable,
InvalidVariableValue), and alias the compiler's error types and the type
checker's error kinds from the root package with the same field-stability
contract as the interpreter's.

Refs EN-2833
@Azorlogh
Azorlogh force-pushed the claude/export-compiler-errors branch from 1352abf to f779f19 Compare October 9, 2026 13:52
@NumaryBot NumaryBot added risk: medium NumaryBot classified this pull request as medium risk. bot-reviewed NumaryBot completed its review workflow for the current head. review-inconclusive and removed risk: medium NumaryBot classified this pull request as medium risk. bot-reviewed NumaryBot completed its review workflow for the current head. review-inconclusive labels Oct 9, 2026
@ascandone
ascandone self-requested a review October 9, 2026 14:28
@Azorlogh
Azorlogh merged commit 6fa3191 into main Oct 9, 2026
9 of 16 checks passed
@Azorlogh
Azorlogh deleted the claude/export-compiler-errors branch October 9, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-reviewed NumaryBot completed its review workflow for the current head. review-inconclusive risk: medium NumaryBot classified this pull request as medium risk.

Development

Successfully merging this pull request may close these issues.

3 participants