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 12:55:42 +00:00
parent 2a19dc7c63
commit 00403eb75e

View file

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