fix: metamodel query error handling#148
Merged
asharkhan3101 merged 1 commit intoJul 22, 2026
Merged
Conversation
asharkhan3101
approved these changes
Jul 22, 2026
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.
Fix the metamodel query irrecoverable error handling as we discussed in #145 (comment)
Expected behavior
When executing the rewritten initialization block:
In the highly unlikely event that
Query::newreturns anErr(e.g., due to a broken embedded SCM query structure), the system undergoes a graceful, multi-stage teardown instead of an abrupt termination:Synchronous Logging Dispatch (
.inspect_err):The
inspect_errcombinator immediately intercepts theQueryErrorand triggers thetrace_errorclosure. This formats and dispatches the details straight into the logging pipeline viatracing::error!.ClientLoggercaptures this event and performs atry_sendinto thetokio::sync::mpscbuffer queue.Panicking with Context (
.expect):Since the result evaluates to
Err,.expect()forces the current thread to panic, carrying the message"Tree-sitter query compilation failed".Runtime Interception (
CatchUnwindLayer):Because the
async_lspserver topology utilizesCatchUnwindLayer::default(), the panic does not instantly kill the OS process.main().Guaranteed Buffer Flushing via RAII (
WorkerGuard):As
main()completes its termination lifecycle, Rust drops all remaining active resources in local scopes._log_guardvariable (returned fromlog::install) is dropped. Its underlyingtracing_appender::non_blocking::WorkerGuarddestructor explicitly forces a blocking, synchronous flush of all remaining logs sitting in the background thread directly intoprotols.log.std::thread::sleep(50)pauses, guaranteeing zero diagnostic data loss.I've tested this error on VS Code client:
and neovim:
So it depends on the client, whether the stderr text will be displayed.
However, the log file
protols.logincludes this:I expect that only
protolsdevelopers could theoretically encounter this issue during internal development. It will never be released to regular users, as our test suite would fail the build beforehand. So it seem to be a good UX/DX.