Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(inspect): ensure non-compact output when object literal has newline in entry text #18366

Merged
merged 3 commits into from
Mar 23, 2023

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Mar 22, 2023

Fixes Deno.inspect to make an object literal non-compact when an entry has multiple lines in it.


Edit: Old information below

I develop in V:\deno and this test was failing for me because the file path was short enough that it changed the formatting. For example:

$ deno run asdf.ts
error: Uncaught { foo: Error
    at file:///home/david/dev/deno/asdf.ts:2:8 }
$ deno run cli/tests/testdata/run/nested_error.ts
error: Uncaught {
  foo: Error
    at file:///home/david/dev/deno/cli/tests/testdata/run/nested_error.ts:2:8
}
$ cat asdf.ts
throw {
  foo: new Error(),
};
$ cat cli/tests/testdata/run/nested_error.ts
throw {
  foo: new Error(),
};

This PR moves the test into a sub directory, which will cause the formatting to be the same for long and short dev paths.

@dsherret dsherret requested a review from bartlomieju March 22, 2023 20:34
@dsherret dsherret changed the title tests: fix nested_error test to not fail on dev environments with a short file path test: fix nested_error test to not fail on dev environments with a short file path Mar 22, 2023
@dsherret
Copy link
Member Author

I will look into why it's formatting this way for short paths actually.

@dsherret dsherret changed the title test: fix nested_error test to not fail on dev environments with a short file path fix(inspect): ensure non-compact output when object literal has newline in entry text Mar 22, 2023
args: "run run/nested_error.ts",
output: "run/nested_error.ts.out",
args: "run run/nested_error/main.ts",
output: "run/nested_error/main.ts.out",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally moved this file to increase the path length, but I kept it here as part of this PR because it's less cluttered.

totalLength > LINE_BREAKING_LENGTH ||
!inspectOptions.compact ||
StringPrototypeIncludes(entriesText, "\n")
) {
Copy link
Member Author

@dsherret dsherret Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to write a test, but you can see here this is fixed:

> cargo run
Deno 1.31.3
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> Deno.inspect({ test: new Error() })
"{\n  test: Error\n    at <anonymous>:3:11\n}"
> close()
> deno
Deno 1.31.3+8bcffff
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> Deno.inspect({ test: new Error() })
"{ test: Error\n    at <anonymous>:3:11 }"

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, this one was fun to debug.

@dsherret dsherret merged commit 81c5ddf into denoland:main Mar 23, 2023
@dsherret dsherret deleted the chore_fix_nested_error_short_paths branch March 23, 2023 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants