errors: unify public runtime exceptions around Lua.RuntimeException#390
Merged
Conversation
The public exception surface leaked VM internals: Lua.call_function/3
returned raw Lua.VM.{RuntimeError,TypeError,ArgumentError,...} structs,
inconsistently suffixed `*Error` and namespaced under the implementation
detail Lua.VM.
Make the public surface exactly two exceptions, both `*Exception`:
* Lua.CompilerException — compile/parse failures
* Lua.RuntimeException — every runtime failure
The five Lua.VM.*Error structs are now internal (@moduledoc false): they
are wrapped into Lua.RuntimeException before crossing any API boundary,
so they never surface raw and are no longer documented as public. They
stay under Lua.VM (the correct home for internal VM error types), which
leaves the ~219 stdlib raise sites untouched.
Lua.RuntimeException grows two fields so callers can still discriminate:
* :kind — :error | :type | :argument | :assertion | :internal
* :value — the raised Lua value, exactly as pcall hands it back (§6.1)
(:original still carries the internal VM struct for deep inspection.)
call_function/3 now returns {:error, %Lua.RuntimeException{}, lua}
uniformly. Its :value now matches in-Lua pcall for string errors (both
give "<eval>:1: boom"); previously it returned the un-prefixed "boom".
Marking the VM error structs @moduledoc false hid them from ExDoc, so the CHANGELOG's backtick references to them tripped "references a hidden module" under `mix docs --warnings-as-errors`. Align the docs config with the new stance: the VM structs are internal, so remove them from @public_modules and the "Errors" group (leaving only Lua.RuntimeException and Lua.CompilerException, plus the public Lua.Parser.Error), drop their now-unused aliases, and add them to skip_code_autolink_to so prose references render as plain code.
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.
Context
The public exception surface was inconsistent and leaked VM internals.
Lua.call_function/3returned rawLua.VM.RuntimeError/Lua.VM.TypeError/Lua.VM.ArgumentError/ … structs — inconsistently suffixed*Errorand namespaced under the implementation detailLua.VM. Since we're pre-1.0 (1.0.0-rc), this is the moment to settle the surface before it freezes.What changed
The public exception surface is now exactly two types, both
*Exception, neither underLua.VM:Lua.CompilerException— compile/parse failuresLua.RuntimeException— every runtime failureThe five
Lua.VM.*Errorstructs are now internal (@moduledoc false): they're wrapped intoLua.RuntimeExceptionbefore crossing any API boundary, so they never surface raw. They stay underLua.VM— the correct home for internal VM error types once they're not user-facing — which leaves the ~219 stdlib raise sites untouched (a low-risk change concentrated at the boundary).Lua.RuntimeExceptiongrows two fields so callers can still discriminate::kind—:error | :type | :argument | :assertion | :internal:value— the raised Lua value, exactly aspcallhands it back (§6.1):originalstill carries the internal VM struct for deep inspection)Lua.call_function/3now returns{:error, %Lua.RuntimeException{}, lua}uniformly. A side benefit: its:valuenow matches in-Luapcallfor string errors (both give"<eval>:1: boom"); previously it returned the un-prefixed"boom".Files
lib/lua/runtime_exception.ex— new:kind/:value; wrap clause derives them (value via existingProtectedCall.error_value/1)lib/lua.ex—finish_call/2wraps VM exceptions; updatedcall_function/3docslib/lua/vm/*_error.ex(×5) —@moduledoc false, prose preserved as commentsCHANGELOG.md— public surface +call_function/3return-type entries:kind/:valuecoverageVerification
mix test— 2598 passed (67 doctests, 56 properties), 7 skippedmix compile --warnings-as-errorsclean;mix formatcleancall_function/3returns%Lua.RuntimeException{kind:, value:, original:}; in-Luapcallrecovery unchanged ({false, "<eval>:1: boom"})Note for review
Internal structs kept their
*Errornames (idiomatic Elixir for internal building blocks, and no longer user-facing). Renaming them to*Exceptiontoo is a mechanical follow-up if preferred.