Repository navigation
Truncate source lines in error messages - #9832
Conversation
bca5993 to
b0c293f
Compare
|
❌ @Jarred-Sumner 3 files with test failures on linux-x64-baseline: |
|
❌ @Jarred-Sumner 2 files with test failures on linux-x64: |
|
❌ @Jarred-Sumner 2 files with test failures on bun-darwin-aarch64: |
|
❌ @Jarred-Sumner 2 files with test failures on bun-darwin-x64:
|
| cmake_policy(SET CMP0067 NEW) | ||
|
|
||
| set(Bun_VERSION "1.1.0") | ||
| set(Bun_VERSION "1.1.1") |
There was a problem hiding this comment.
I've seen a few diff v1_1_1 things or was that a 1_1_0 thing. This should be in a sep PR though as it's versioning related.
| // This is a longer number than necessary because we don't handle this case very well | ||
| // At the very least, we shouldn't dump 100 KB of minified code into your terminal. | ||
| const max_line_length_with_divot = 512; | ||
| const max_line_length = 1024; |
There was a problem hiding this comment.
I'm fine with less. Usually a line is like 80 to 120 chars.
| bun.fmt.fmtJavaScript(std.mem.trimRight(u8, std.mem.trim(u8, source.text.slice(), "\n"), "\t "), allow_ansi_color), | ||
| }, | ||
| ); | ||
| const trimmed = std.mem.trimRight(u8, std.mem.trim(u8, source.text.slice(), "\n"), "\t "); |
There was a problem hiding this comment.
The snip to \n covers \r\n too (is my assumption)
| const text = trimmed[0..@min(trimmed.len, max_line_length)]; | ||
|
|
||
| if (text.len != trimmed.len) { | ||
| const fmt = if (comptime allow_ansi_color) "<r><d> | ... truncated <r>\n" else "\n"; |
There was a problem hiding this comment.
Can has ellipsis here? “…” (U+2026). (if it's okay for Windows)
| defer source.text.deinit(); | ||
| const text = source.text.slice(); | ||
| const remainder = std.mem.trimRight(u8, std.mem.trim(u8, text, "\n"), "\t "); | ||
| const trimmed = std.mem.trimRight(u8, std.mem.trim(u8, text, "\n"), "\t "); |
There was a problem hiding this comment.
This timming is done twice (turn into an inlined function?)
| if (!top.position.isInvalid()) { | ||
| const indent = max_line_number_pad + " | ".len + @as(u64, @intCast(top.position.column_start)); | ||
| if (clamped.len != trimmed.len) { | ||
| const fmt = if (comptime allow_ansi_color) "<r><d> | ... truncated <r>\n\n" else "\n\n"; |
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
| 'use strict';var l=Symbol.for("react.element"),n=Symbol.for("react.portal"),p=Symbol.for("react.fragment"),q=Symbol.for("react.strict_mode"),r=Symbol.for("react.profiler"),t=Symbol.for("react.provider"),u=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),w=Symbol.for("react.suspense"),x=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),z=Symbol.iterator;function A(a){if(null===a||"object"!==typeof a)return null;a=z&&a[z]||a["@@iterator"];return"function"===typeof a?a:null} |
There was a problem hiding this comment.
Given the xz minified/obfuscated payload test stuff in the headlines for ease of future us and transparency could we just minify our own test file via our API.
| test("Error inside minified file (color) ", () => { | ||
| try { | ||
| require("./inspect-error-fixture.min.js"); | ||
| expect.unreachable(); |
There was a problem hiding this comment.
Missing documentation for expect.unreachable(). (would be nice to know which API we are mimicking (e.g. jest, vitest, etc).
#7131
|
I love these kinds of enhancements ❤️ |
|
❌ @Jarred-Sumner 8 files with test failures on bun-windows-x86_64-haswell
|
What does this PR do?
When a minified file throws an exception in Bun, the source lines can be extremely long
This causes two problems:
This PR truncates source text to be up to 1024 bytes per line. The divot will no longer appear if the line is > 512 bytes. The goal is to avoid the above two problems without debugging harder. So we use a probably longer than necessary limit.
These numbers are arbitrary and a better solution overall would be to "scroll" within the lines to the relevant parts. I don't trust our source maps are reliable enough right now to do that well, so this is a compromise until then.
After:
Before:
With lots of scrolling:
How did you verify your code works?
There are a couple snapshot tests