mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
twiddle with formatting
This commit is contained in:
@@ -511,6 +511,11 @@ pub const ZigStackFrame = extern struct {
|
||||
|
||||
root_path: string = "",
|
||||
pub fn format(this: SourceURLFormatter, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
|
||||
if (this.enable_color) {
|
||||
try writer.writeAll(Output.prettyFmt("<r><cyan>", true));
|
||||
}
|
||||
|
||||
var source_slice = this.source_url.slice();
|
||||
if (this.origin) |origin| {
|
||||
try writer.writeAll(origin.displayProtocol());
|
||||
try writer.writeAll("://");
|
||||
@@ -518,20 +523,47 @@ pub const ZigStackFrame = extern struct {
|
||||
try writer.writeAll(":");
|
||||
try writer.writeAll(origin.port);
|
||||
try writer.writeAll("/blob:");
|
||||
}
|
||||
|
||||
var source_slice = this.source_url.slice();
|
||||
if (strings.startsWith(source_slice, this.root_path)) {
|
||||
source_slice = source_slice[this.root_path.len..];
|
||||
if (strings.startsWith(source_slice, this.root_path)) {
|
||||
source_slice = source_slice[this.root_path.len..];
|
||||
}
|
||||
}
|
||||
|
||||
try writer.writeAll(source_slice);
|
||||
|
||||
if (this.enable_color) {
|
||||
if (this.position.line > -1) {
|
||||
try writer.writeAll(comptime Output.prettyFmt("<r>", true));
|
||||
} else {
|
||||
try writer.writeAll(comptime Output.prettyFmt("<r>", true));
|
||||
}
|
||||
}
|
||||
|
||||
if (this.position.line > -1 and this.position.column_start > -1) {
|
||||
try std.fmt.format(writer, ":{d}:{d}", .{ this.position.line + 1, this.position.column_start });
|
||||
if (this.enable_color) {
|
||||
try std.fmt.format(
|
||||
writer,
|
||||
// :
|
||||
comptime Output.prettyFmt("<d>:<r><yellow>{d}<r><d>:<yellow>{d}<r>", true),
|
||||
.{ this.position.line + 1, this.position.column_start },
|
||||
);
|
||||
} else {
|
||||
try std.fmt.format(writer, ":{d}:{d}", .{ this.position.line + 1, this.position.column_start });
|
||||
}
|
||||
} else if (this.position.line > -1) {
|
||||
try std.fmt.format(writer, ":{d}", .{
|
||||
this.position.line + 1,
|
||||
});
|
||||
if (this.enable_color) {
|
||||
try std.fmt.format(
|
||||
writer,
|
||||
comptime Output.prettyFmt("<d>:<r><yellow>{d}<r>", true),
|
||||
.{
|
||||
this.position.line + 1,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
try std.fmt.format(writer, ":{d}", .{
|
||||
this.position.line + 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -549,13 +581,15 @@ pub const ZigStackFrame = extern struct {
|
||||
try writer.writeAll("(eval)");
|
||||
},
|
||||
.Module => {
|
||||
try writer.writeAll("(esm)");
|
||||
// try writer.writeAll("(esm)");
|
||||
},
|
||||
.Function => {
|
||||
if (name.len > 0) {
|
||||
try std.fmt.format(writer, "{s}", .{name});
|
||||
} else {
|
||||
try writer.writeAll("(anonymous)");
|
||||
if (this.enable_color) {
|
||||
try std.fmt.format(writer, comptime Output.prettyFmt("<r><b><i>{s}<r>", true), .{name});
|
||||
} else {
|
||||
try std.fmt.format(writer, "{s}", .{name});
|
||||
}
|
||||
}
|
||||
},
|
||||
.Global => {
|
||||
|
||||
@@ -3050,22 +3050,42 @@ pub const VirtualMachine = struct {
|
||||
const func = frame.function_name.slice();
|
||||
if (file.len == 0 and func.len == 0) continue;
|
||||
|
||||
try writer.print(
|
||||
comptime Output.prettyFmt(
|
||||
"<r> <d>at <r>{any} <d>(<r>{any}<d>)<r>\n",
|
||||
allow_ansi_colors,
|
||||
),
|
||||
.{
|
||||
frame.nameFormatter(
|
||||
const has_name = std.fmt.count("{any}", .{frame.nameFormatter(
|
||||
false,
|
||||
)}) > 0;
|
||||
|
||||
if (has_name) {
|
||||
try writer.print(
|
||||
comptime Output.prettyFmt(
|
||||
"<r> <d>at <r>{any}<d> (<r>{any}<d>)<r>\n",
|
||||
allow_ansi_colors,
|
||||
),
|
||||
frame.sourceURLFormatter(
|
||||
dir,
|
||||
origin,
|
||||
.{
|
||||
frame.nameFormatter(
|
||||
allow_ansi_colors,
|
||||
),
|
||||
frame.sourceURLFormatter(
|
||||
dir,
|
||||
origin,
|
||||
allow_ansi_colors,
|
||||
),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
try writer.print(
|
||||
comptime Output.prettyFmt(
|
||||
"<r> <d>at <r>{any}\n",
|
||||
allow_ansi_colors,
|
||||
),
|
||||
},
|
||||
);
|
||||
.{
|
||||
frame.sourceURLFormatter(
|
||||
dir,
|
||||
origin,
|
||||
allow_ansi_colors,
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3158,7 +3178,11 @@ pub const VirtualMachine = struct {
|
||||
) catch unreachable;
|
||||
}
|
||||
|
||||
const name = exception.name;
|
||||
var name = exception.name;
|
||||
if (strings.eqlComptime(exception.name.slice(), "Error")) {
|
||||
name = ZigString.init("error");
|
||||
}
|
||||
|
||||
const message = exception.message;
|
||||
var did_print_name = false;
|
||||
if (source_lines.next()) |source| {
|
||||
@@ -3177,7 +3201,7 @@ pub const VirtualMachine = struct {
|
||||
) catch unreachable;
|
||||
|
||||
if (name.len > 0 and message.len > 0) {
|
||||
writer.print(comptime Output.prettyFmt(" <r><red><b>{}<r><d>:<r> <b>{}<r>\n", allow_ansi_color), .{
|
||||
writer.print(comptime Output.prettyFmt(" <r><red>{}<r><d>:<r> <b>{}<r>\n", allow_ansi_color), .{
|
||||
name,
|
||||
message,
|
||||
}) catch unreachable;
|
||||
@@ -3232,7 +3256,7 @@ pub const VirtualMachine = struct {
|
||||
}
|
||||
|
||||
if (name.len > 0 and message.len > 0) {
|
||||
writer.print(comptime Output.prettyFmt(" <r><red><b>{s}<r><d>:<r> <b>{s}<r>\n", allow_ansi_color), .{
|
||||
writer.print(comptime Output.prettyFmt(" <r><red>{s}<r><d>:<r> <b>{s}<r>\n", allow_ansi_color), .{
|
||||
name,
|
||||
message,
|
||||
}) catch unreachable;
|
||||
@@ -3246,14 +3270,14 @@ pub const VirtualMachine = struct {
|
||||
|
||||
if (!did_print_name) {
|
||||
if (name.len > 0 and message.len > 0) {
|
||||
writer.print(comptime Output.prettyFmt("<r><red><b>{s}<r><d>:<r> <b>{s}<r>\n", true), .{
|
||||
writer.print(comptime Output.prettyFmt("<r><red>{s}<r><d>:<r> <b>{s}<r>\n", true), .{
|
||||
name,
|
||||
message,
|
||||
}) catch unreachable;
|
||||
} else if (name.len > 0) {
|
||||
writer.print(comptime Output.prettyFmt("<r><b>{s}<r>\n", true), .{name}) catch unreachable;
|
||||
writer.print(comptime Output.prettyFmt("<r>{s}<r>\n", true), .{name}) catch unreachable;
|
||||
} else if (message.len > 0) {
|
||||
writer.print(comptime Output.prettyFmt("<r><b>{s}<r>\n", true), .{name}) catch unreachable;
|
||||
writer.print(comptime Output.prettyFmt("<r>{s}<r>\n", true), .{name}) catch unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user