aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-09-16 22:52:49 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-09-16 22:52:49 -0700
commitea660b338d6898adce2cc95629cb1461b4333ff8 (patch)
tree496ce03cbb9fed7dfb1dec430fc30dedd64d4ba7
parent8c8dd8b69c15920f3e2c1ef69f2cf0064efb997a (diff)
downloadbun-jarred/cleanup-error.tar.gz
bun-jarred/cleanup-error.tar.zst
bun-jarred/cleanup-error.zip
Use a better error labeljarred/cleanup-error
-rw-r--r--src/bundler/bundle_v2.zig4
-rw-r--r--src/import_record.zig17
2 files changed, 19 insertions, 2 deletions
diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig
index 64aaf54d9..359272e5f 100644
--- a/src/bundler/bundle_v2.zig
+++ b/src/bundler/bundle_v2.zig
@@ -512,7 +512,7 @@ pub const BundleV2 = struct {
import_record.range,
this.graph.allocator,
"Browser build cannot {s} Node.js module: \"{s}\". To use Node.js builtins, set target to 'node' or 'bun'",
- .{ import_record.kind.label(), path_to_use },
+ .{ import_record.kind.errorLabel(), path_to_use },
import_record.kind,
) catch unreachable;
} else {
@@ -1915,7 +1915,7 @@ pub const BundleV2 = struct {
import_record.range,
this.graph.allocator,
"Browser build cannot {s} Node.js builtin: \"{s}\". To use Node.js builtins, set target to 'node' or 'bun'",
- .{ import_record.kind.label(), import_record.path.text },
+ .{ import_record.kind.errorLabel(), import_record.path.text },
import_record.kind,
) catch @panic("unexpected log error");
} else {
diff --git a/src/import_record.zig b/src/import_record.zig
index 3044c9b47..d48cfb1b0 100644
--- a/src/import_record.zig
+++ b/src/import_record.zig
@@ -51,10 +51,27 @@ pub const ImportKind = enum(u8) {
break :brk labels;
};
+ pub const error_labels: Label = brk: {
+ var labels = Label.initFill("");
+ labels.set(ImportKind.entry_point, "entry point");
+ labels.set(ImportKind.stmt, "import");
+ labels.set(ImportKind.require, "require()");
+ labels.set(ImportKind.dynamic, "import()");
+ labels.set(ImportKind.require_resolve, "require.resolve");
+ labels.set(ImportKind.at, "@import");
+ labels.set(ImportKind.url, "url()");
+ labels.set(ImportKind.internal, "<bun internal>");
+ break :brk labels;
+ };
+
pub inline fn label(this: ImportKind) []const u8 {
return all_labels.get(this);
}
+ pub inline fn errorLabel(this: ImportKind) []const u8 {
+ return error_labels.get(this);
+ }
+
pub inline fn isCommonJS(this: ImportKind) bool {
return switch (this) {
.require, .require_resolve => true,