errors: drop the :message field from public runtime exceptions#392
Merged
Conversation
Lua.RuntimeException carried a :message struct field that was populated eagerly for some constructor shapes but left nil for the common case of a wrapped VM exception (rendered lazily to keep the #384 ANSI gate honest). Reading exception.message directly therefore returned nil for most runtime errors out of eval!/call_function — a silent footgun for anyone logging the conventional field. Remove the field entirely and make Exception.message/1 the single renderer, composing lazily from the already-present semantic fields (:original, :kind, :value, :line, :source, :call_stack). Drop the dead {:api_error, ...} clause while here, and normalize Lua.VM.InternalError the same way (its :message was always stringify(value); every raise site passes only value:). Lands before the 1.0.0 tag while the public surface is still unfrozen.
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.
Why
Lua.RuntimeExceptioncarried a:messagestruct field that was inconsistently populated — a rendered string for a few constructor shapes, butnilfor the most common case: a wrapped VM exception out ofeval!/call_function, wheremessage/1renders lazily to keep the ANSI gate honest (#384).So reading
exception.messagedirectly returnednilfor most real runtime errors. Anyone reaching for the conventional field (Logger.error(exception.message)) silently logged nothing. The migration guide even had to warn readers that ":messagemay benil."The data needed to render was already present on semantic fields (
:original,:kind,:value,:line,:source,:call_stack). The:messagefield was pure memoization layered on top — and the one field that misled.Landing this before the
v1.0.0tag while the public surface is still unfrozen.What
lib/lua/runtime_exception.ex— drop:messagefromdefexception.message/1is now total, composing lazily from:original(exception → keyword descriptor → binary →{:badarith}/{:illegal_index}term →inspectfallback), all through the existing single-prefix guard. Constructors store their source on:original(binary now lands there instead ofnil). Delete the dead{:api_error, …}clause — nothing inlib/ever raised it.lib/lua/vm/internal_error.ex— same normalization: drop its redundant:messagefield (always== stringify(value)), add amessage/1callback. Raise sites untouched (all passvalue:).tasks/lua.suite.ex— one dev task built the struct with%{message: …}directly; switched to the string constructor.guides/migrating-to-1.0.md— rewrite the ":messagemay be nil" note to "there is no:messagefield — useException.message/1.":api_errorblock, update binary-clause:originalassertions, pinrefute Map.has_key?(exception, :message), add anInternalErrormessage/1assertion.Verification
mix test— 2597 passed, 7 skippedmix format --check-formatted— cleanerror('boom')→Exception.message/1renders the full string with:kind/:valuepopulated and no:messagekey; binary, keyword, andillegal_indexpaths render unchanged.Note
The removed
:api_errorclause rendered with a distinct"Lua API error: "prefix. Since it was unreachable dead code, it's gone with the clause. If a real host-API failure path ever needs that prefix, it should come back as a semantic:kindrather than a baked-in:messagestring.