elixir-devex: Use structured WasmError exceptions in all core error paths#8
Open
elixir-devex: Use structured WasmError exceptions in all core error paths#8
Conversation
Previously, `use Firebird.TestCase, wasm: Path.join([__DIR__, ...])` crashed with a cryptic CaseClauseError because the macro only handled string literals, :sample, and false. Now any expression that evaluates to a string at runtime is accepted: - Path.join([__DIR__, ...]) - Path.expand(...) - Module attributes (@wasm_path) - Any other expression returning a string If the expression evaluates to a non-string, a clear ArgumentError is raised: 'must resolve to a string path, got: ...' Added tests for: Path.join, Path.expand, module attributes, string literals (regression), and error message format.
Replace bare RuntimeError raises with Firebird.WasmError in: - Firebird.load!/2: file not found, load failures - Firebird.call!/3, call_one!/3: function not found (with 'Did you mean?'), instance stopped, call failures - Firebird.run!/4, run_one!/4: propagate structured errors - Firebird.Runtime.call!/4: same improvements Add new WasmError constructors: - instance_stopped/1: clear message when calling on dead instance - call_failed/3: context-aware hints (timeout, arity mismatch, etc.) Benefits: - All errors are rescuable with 'rescue e in Firebird.WasmError' - Structured fields (reason, function, wasm_path) for programmatic handling - Every error includes actionable fix suggestions - 'Did you mean?' suggestions via Jaro distance on function names Update 12 test files to expect WasmError instead of RuntimeError. Add comprehensive test coverage in dx_error_quality_test.exs.
- Run mix format on entire project - Fix unused generate_expr/3 in wat_gen.ex - Fix unused module_name variable in firebird.compile.ex - Register @wasm attribute in wasm_modules to suppress warnings - Silence FastNif load warning (expected in most environments)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By Grumpy
What
Replace bare
RuntimeErrorraises with structuredFirebird.WasmErrorexceptions across all core API error paths (load!,call!,call_one!,run!,run_one!,pipe!,map,quick).Why
Before this change, errors from Firebird raised generic
RuntimeErrorwith string messages. Developers couldn't:rescue e in Firebird.WasmError)e.reason,e.function,e.wasm_path)Changes
New
WasmErrorconstructors:instance_stopped/1— clear message when calling on a dead instance with reload instructionscall_failed/3— context-aware hints (detects timeout, arity mismatch, exit reasons)Updated error paths (3 lib files):
Firebird.load!/2: raisesWasmError.file_not_foundorWasmError.load_failedFirebird.call!/3,call_one!/3: raisesWasmError.function_not_found(with 'Did you mean?' via Jaro distance),WasmError.instance_stopped, orWasmError.call_failedFirebird.run!/4,run_one!/4: propagates structured errorsFirebird.Runtime.call!/4: same structured error patternUpdated 12 test files to expect
WasmErrorinstead ofRuntimeError, plus comprehensive new test coverage indx_error_quality_test.exs.