Repository navigation
Description
Problem
The web editor renders nonsense error prefixes because there are three differently-numbered ErrorCode enums and the diagram casts wire codes from one numbering into another:
- Rust engine enum
simlin_engine::common::ErrorCode(src/simlin-engine/src/common.rs): the full enum, whereNoAppInUnits = 33andUnitMismatch = 44. - libsimlin C-ABI enum
SimlinErrorCode(src/libsimlin/src/lib.rs:96): a collapsed enum where all the units-definition codes collapse intoGeneric = 32, soUnitMismatch = 33andBadOverride = 34. This is the numbering that actually crosses the WASM/FFI boundary in error details (From<engine::ErrorCode> for SimlinErrorCodeat lib.rs:238 does the collapse). - TS enum
ErrorCodeinsrc/core/errors.ts(with a hand-maintained duplicate copy insrc/engine/src/errors.ts): a copy of the engine numbering, where33 = NoAppInUnits,34 = NoSubscriptInUnits,44 = UnitMismatch, witherrorCodeDescription()mapping codes to human strings.
The diagram's convertErrorDetails in src/diagram/project-controller.ts (lines 206, 220; same pattern again at 1111, 1116) does:
code: err.code as unknown as ErrorCode,casting a libsimlin wire code into the TS engine-numbered enum. Every wire code >= 33 is mistranslated:
- libsimlin
UnitMismatch(33) renders as TSNoAppInUnits-- observed symptom: a unit-inference warning displays inErrorDetails.tsxas "model error: Function calls are not allowed in unit definition: ..." - libsimlin
BadOverride(34) would render as TSNoSubscriptInUnits("subscripts are not allowed in unit definitions"), etc.
Why it matters
Correctness of user-facing diagnostics: users see confidently wrong error explanations for real model problems (unit mismatches are common), which actively misleads debugging. It also undermines any code that branches on specific TS ErrorCode values for FFI-sourced errors.
Components affected
src/diagram(project-controller.tsconvertErrorDetails,ErrorDetails.tsxdisplay)src/core/errors.tsandsrc/engine/src/errors.ts(two hand-maintained identical copies; neither is generated from or checked against the Rust enums, so this class of skew will recur without a guard)src/libsimlin(source of the wire numbering)
Possible approaches
- Make the TS
ErrorCodeenum mirror the libsimlin C-ABI numbering (the actual wire format), or convert codes explicitly at the FFI boundary instead of casting. - Deduplicate
src/core/errors.tsvssrc/engine/src/errors.tsinto a single source. - Add a cross-language guard test (or codegen) that asserts the TS numbering matches
SimlinErrorCodeinsrc/libsimlin/src/lib.rs, so future enum edits cannot silently skew.
Context
Identified while debugging why a unit-inference warning rendered with a "Function calls are not allowed in unit definition" prefix in the web editor.
Activity
bpowers commentedon Jul 4, 2026
Fixed in ed29894 (diagram: fix unit-error display). The TS ErrorCode enums in src/core/errors.ts and src/engine/src/errors.ts now mirror the libsimlin wire numbering (UnitMismatch = 33, BadOverride = 34), the units-definition parse codes are mapped faithfully across the FFI as additive discriminants 35-45 instead of collapsing to Generic, and a comment on each enum pins the sync invariant. The GUI additionally stopped rendering the terminal-formatted message: the bare reason now crosses the FFI in a separate details field.