Repository navigation
Return errors instead of raising on corrupt beam in docs and ExCk reads - #348
Merged
Merged
Conversation
Code.fetch_docs/1 delegates to :beam_lib, which only catches throws. A
malformed or truncated .beam makes :beam_lib.read_info/1 raise (e.g.
MatchError from a badarg in binary_to_atom), which escaped completion
and hover via Normalized.Code.get_docs/2 and callback_documentation/1.
- Normalized.Code.fetch_docs/1 now catches any raise/exit/throw and
returns {:error, :chunk_not_found}; callback_documentation/1 goes
through it.
- ExCkReader's on-disk :beam_lib.chunks/2 path catches the same and
falls through to the existing binary fallback.
Tests mirror the typespec corrupt-beam test from #346.
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.
Problem
Completion crashes when a
.beamis malformed or truncated (e.g. being rewritten by a concurrent compile).Code.fetch_docs/1delegates to:beam_lib, which only catches throws, so the error escapes:Same root cause as #346 (
Normalized.Typespec).Changes
Normalized.Code.fetch_docs/1catches any raise/exit/throw fromCode.fetch_docsand returns{:error, :chunk_not_found}.callback_documentation/1now goes through this wrapper.ExCkReaderon-disk:beam_lib.chunks/2path catches the same and falls through to the existing binary fallback.BuiltinFunctionsCode.fetch_docs(Module)runs at compile time on a fixed module, so it cannot read an arbitrary beam at request time.Tests
Normalized.CodeTest: corrupt beam (byte flipped in the atom table) makesfetch_docs/1andget_docs/2return error/nil. Fails on master with the MatchError above.ExCkReaderTest: same corruption on the on-disk path; assertsread_chunk/2returns a tagged result and does not raise. Fails on master.mix teston the touched files: 45 passed. Full suite has the same 58 failures with and without this change (pre-existing ElixirTypes/BindingDescr property tests on the local 1.21-dev toolchain).