fix: guard error handler against non-object thrown values#969
fix: guard error handler against non-object thrown values#969AI-Reviewer-QS wants to merge 1 commit intoChromeDevTools:mainfrom
Conversation
The `in` operator throws a TypeError when its right-hand operand is not an object. In the tool execution error handler, both `'message' in err` and `'cause' in err` will crash if the caught value is a primitive (null, string, number, undefined). Add `typeof err === 'object'` checks before using the `in` operator to ensure primitive thrown values are safely converted to strings.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Is there a scenario where a non Error object is thrown? |
|
We can easily enforce this with |
would not help for errors thrown by dependencies |
|
I think this is redundant for now, please let us know if you have a scenario where a non-object is thrown. |
Summary
inoperator throws aTypeErrorwhen its right-hand operand is not an object'message' in errand'cause' in errcrash if the caught value is a primitive (null, string, number, undefined)typeof err === 'object'checks before using theinoperator to ensure primitive thrown values are safely converted to stringsReproduction
Test plan
throw nullthrow "string"throw 42throw new Error("msg")still workscauseproperty still includes cause message