mirror of
https://github.com/denoland/deno.git
synced 2024-12-26 09:10:40 -05:00
fix(console): handle error when inspecting promise-like (#19083)
Fixes https://discord.com/channels/684898665143206084/684911491035430919/1105900195406958672. This was caused by: - A `TypeError` from `core.getPromiseDetails()` for promise-likes which also lead to that code path. - Swallowing internal formatting errors by returning `undefined`. I've made it so that a special message is formatted in that case instead (note that this case is fixed now): ![image](https://github.com/denoland/deno/assets/29990554/65bb9612-60b2-4e31-bf5e-e20976601593)
This commit is contained in:
parent
2ba9ccc1ab
commit
ffb0318e4a
2 changed files with 21 additions and 29 deletions
|
@ -2235,6 +2235,13 @@ Deno.test(function inspectWithPrototypePollution() {
|
|||
}
|
||||
});
|
||||
|
||||
Deno.test(function inspectPromiseLike() {
|
||||
assertEquals(
|
||||
Deno.inspect(Object.create(Promise.prototype)),
|
||||
"Promise { <unknown> }",
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test(function inspectorMethods() {
|
||||
console.timeStamp("test");
|
||||
console.profile("test");
|
||||
|
|
|
@ -161,6 +161,7 @@ const styles = {
|
|||
// TODO(BridgeAR): Highlight regular expressions properly.
|
||||
regexp: "red",
|
||||
module: "underline",
|
||||
internalError: "red",
|
||||
};
|
||||
|
||||
const defaultFG = 39;
|
||||
|
@ -1022,7 +1023,6 @@ function formatRaw(ctx, value, recurseTimes, typedArray, proxyDetails) {
|
|||
ArrayPrototypePush(ctx.seen, value);
|
||||
ctx.currentDepth = recurseTimes;
|
||||
let output;
|
||||
const indentationLvl = ctx.indentationLvl;
|
||||
try {
|
||||
output = formatter(ctx, value, recurseTimes);
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
|
@ -1034,13 +1034,12 @@ function formatRaw(ctx, value, recurseTimes, typedArray, proxyDetails) {
|
|||
if (protoProps !== undefined) {
|
||||
ArrayPrototypePushApply(output, protoProps);
|
||||
}
|
||||
} catch (err) {
|
||||
const constructorName = StringPrototypeSlice(
|
||||
getCtxStyle(value, constructor, tag),
|
||||
0,
|
||||
-1,
|
||||
} catch (error) {
|
||||
// TODO(wafuwafu13): Implement stack overflow check
|
||||
return ctx.stylize(
|
||||
`[Internal Formatting Error] ${error.stack}`,
|
||||
"internalError",
|
||||
);
|
||||
return handleMaxCallStackSize(ctx, err, constructorName, indentationLvl);
|
||||
}
|
||||
|
||||
if (ctx.circular !== undefined) {
|
||||
|
@ -1658,8 +1657,14 @@ const PromiseState = {
|
|||
|
||||
function formatPromise(ctx, value, recurseTimes) {
|
||||
let output;
|
||||
// TODO(wafuwafu13): Implement
|
||||
const { 0: state, 1: result } = core.getPromiseDetails(value);
|
||||
let opResult;
|
||||
// This op will fail for non-promises, but we get here for some promise-likes.
|
||||
try {
|
||||
opResult = core.getPromiseDetails(value);
|
||||
} catch {
|
||||
return [ctx.stylize("<unknown>", "special")];
|
||||
}
|
||||
const { 0: state, 1: result } = opResult;
|
||||
if (state === PromiseState.Pending) {
|
||||
output = [ctx.stylize("<pending>", "special")];
|
||||
} else {
|
||||
|
@ -1770,26 +1775,6 @@ function formatProperty(
|
|||
return `${name}:${extra}${str}`;
|
||||
}
|
||||
|
||||
function handleMaxCallStackSize(
|
||||
_ctx,
|
||||
_err,
|
||||
_constructorName,
|
||||
_indentationLvl,
|
||||
) {
|
||||
// TODO(wafuwafu13): Implement
|
||||
// if (isStackOverflowError(err)) {
|
||||
// ctx.seen.pop();
|
||||
// ctx.indentationLvl = indentationLvl;
|
||||
// return ctx.stylize(
|
||||
// `[${constructorName}: Inspection interrupted ` +
|
||||
// 'prematurely. Maximum call stack size exceeded.]',
|
||||
// 'special'
|
||||
// );
|
||||
// }
|
||||
// /* c8 ignore next */
|
||||
// assert.fail(err.stack);
|
||||
}
|
||||
|
||||
const colorRegExp = new SafeRegExp("\u001b\\[\\d\\d?m", "g");
|
||||
function removeColors(str) {
|
||||
return StringPrototypeReplace(str, colorRegExp, "");
|
||||
|
|
Loading…
Reference in a new issue