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

Cleanup how build errors are displayed slightly #7223

Merged
merged 11 commits into from Nov 20, 2023

Conversation

Jarred-Sumner
Copy link
Collaborator

@Jarred-Sumner Jarred-Sumner commented Nov 19, 2023

What does this PR do?

Two things:

Formatting tweaks

  • Removes extra newlines
  • Fixes logger.rangeOfIdentifier to include the complete length of the identifier (usage of defer broke that)
  • Making the selected portion colored is too intense IMO for longer lines
Before:
image
After:
image

Build-time error for unsupported ESM<>CommonJS features

You can use require and import in the same file in Bun, but you cannot use import and module.exports in the same file. You also cannot use exports, module, with or top-level return.

Currently, we rely on JavaScriptCore's errors for these things, but they're really hard to read and don't give us an easy way to show a stack trace pointing to which line exactly caused it.

This moves those errors to build-time.

Input:
import "abc";

with (Bun) {
  write("/tmp/file.txt", escapeHTML(file("/tmp/file.html").text()));
  console.log({
    contents: file("/tmp/file.txt").text(),
  });
}
Before (note how it says "import call"):
image
After:
image
Input:
import _ from "lodash";
module.exports = _.constant(42);
Before:
image
After:
image

How did you verify your code works?

I wrote a few tests

Copy link

github-actions bot commented Nov 19, 2023

@Jarred-Sumner 4 files with test failures on bun-darwin-aarch64:

  • test/integration/next/default-pages-dir/test/dev-server.test.ts
  • test/js/bun/test/test-test.test.ts
  • test/js/bun/util/which.test.ts
  • test/js/web/worker.test.ts

View test output

#c5fde7b556fbfd57ed76fd39e264bc6b23c09b6b

Copy link

github-actions bot commented Nov 19, 2023

✅ test failures on linux-x64-baseline have been resolved.

#c5fde7b556fbfd57ed76fd39e264bc6b23c09b6b

Copy link

github-actions bot commented Nov 19, 2023

@Jarred-Sumner 1 files with test failures on linux-x64:

  • test/integration/next/default-pages-dir/test/next-build.test.ts

View test output

#c5fde7b556fbfd57ed76fd39e264bc6b23c09b6b

Copy link

github-actions bot commented Nov 19, 2023

@Jarred-Sumner 8 files with test failures on bun-darwin-x64:

  • test/integration/next/default-pages-dir/test/next-build.test.ts
  • test/js/bun/spawn/spawn-streaming-stdout.test.ts
  • test/js/bun/util/filesink.test.ts
  • test/js/bun/util/which.test.ts
  • test/js/node/fs/fs.test.ts
  • test/js/third_party/webpack/webpack.test.ts
  • test/js/web/timers/setInterval.test.js
  • test/js/web/timers/setTimeout.test.js

View test output

#c5fde7b556fbfd57ed76fd39e264bc6b23c09b6b

Copy link

github-actions bot commented Nov 19, 2023

@Jarred-Sumner 8 files with test failures on bun-darwin-x64-baseline:

  • test/integration/next/default-pages-dir/test/dev-server.test.ts
  • test/js/bun/spawn/spawn-streaming-stdout.test.ts
  • test/js/bun/util/filesink.test.ts
  • test/js/bun/util/which.test.ts
  • test/js/node/fs/fs.test.ts
  • test/js/node/watch/fs.watchFile.test.ts
  • test/js/third_party/webpack/webpack.test.ts
  • test/js/web/timers/setTimeout.test.js

View test output

#c5fde7b556fbfd57ed76fd39e264bc6b23c09b6b

if (after.len > 40) {
after = after[0..40];
}
try to.writeAll(after);
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we also need a color reset here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh, I don't think we do because it would've reset on line 341

@Jarred-Sumner Jarred-Sumner merged commit bf32d36 into main Nov 20, 2023
20 of 28 checks passed
@Jarred-Sumner Jarred-Sumner deleted the jarred/cleanup-errors branch November 20, 2023 23:07
ryoppippi pushed a commit to ryoppippi/bun that referenced this pull request Feb 1, 2024
* Cleanup error formatting a little

* Add error for using import statement with CommonJS-only features

* Update js_ast.zig

* Further tweaks to formatting, also print error.cause

* Add some snapshot tests for errors

* Make these snapshot tests

* Ignore mimalloc warnings

* Update error message parsing in bundling tests

* Increase timeout on the test

* Update expectBundled.ts

* Update test

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
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.

None yet

2 participants