fix(cli): handle recoverable errors gracefully and remove panics #4798#4816
Open
Shivampal157 wants to merge 2 commits intoboa-dev:mainfrom
Open
fix(cli): handle recoverable errors gracefully and remove panics #4798#4816Shivampal157 wants to merge 2 commits intoboa-dev:mainfrom
Shivampal157 wants to merge 2 commits intoboa-dev:mainfrom
Conversation
Test262 conformance changes
Fixed tests (2):Broken tests (305):Tested main commit: |
Member
|
Needs a rebase first |
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.
This PR addresses issue #4798 by refactoring the CLI module to eliminate potential panics on recoverable errors. I have replaced several instances of .unwrap() and .expect() with proper Rust error handling patterns, specifically using the ? operator for error propagation and map_err for context-aware reporting.
Key Changes:
Error Propagation in main.rs: Converted AST serialization and runtime registration paths to return Result. This ensures that issues like circular references or initialization failures are caught and reported instead of crashing the process.
Robust Mutex Handling in logger.rs: Switched from .expect() to unwrap_or_else when locking the printer mutex. This allows the CLI to remain functional even if a previous thread left the mutex in a poisoned state.
Safe Regex in helper.rs: Handled regex compilation results gracefully. If a pattern fails to compile (e.g., due to invalid characters), the CLI now simply disables highlighting for that segment rather than panicking.
Debug Module Refactor: Updated init_boa_debug_object to propagate errors back to the caller, ensuring a clean exit on failure.
Verification & Testing:
I have manually verified these fixes against the reproduction steps provided in the issue:
Missing Files: Verified that ./boa nonexistent.js now outputs a clean "failed to read file" error with an exit code of 1.
Malformed JS: Confirmed that syntax errors are caught and reported without triggering a panic.
Permissions: Tested with restricted file access to ensure the I/O error path works as expected.