Bug 1873150 - [devtools] Throw in getPreview if evaluated expression has syntax error. r=ochameau,devtools-reviewers.

This will allow us to be notified about expression we shouldn't try to evaluate.

Differential Revision: https://phabricator.services.mozilla.com/D197762
This commit is contained in:
Nicolas Chevobbe 2024-06-04 08:10:11 +00:00
parent 38dbc8112e
commit 662649f8d5

View file

@ -82,9 +82,21 @@ export function getPreview(target, tokenPos, editor) {
}
}
const { result } = await client.evaluate(expression, {
frameId: selectedFrame.id,
});
const { result, hasException, exception } = await client.evaluate(
expression,
{
frameId: selectedFrame.id,
}
);
// The evaluation shouldn't return an exception.
if (hasException) {
throw new Error(
`Debugger internal exception: Preview for <${expression}> threw a ${
exception?.getGrip()?.class || "Error"
}`
);
}
const resultGrip = getGrip(result);