mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
log error on respondWith rejection,
Former-commit-id: 8f6312a17dc9811d54e4dc31d9ada68e98bae891
This commit is contained in:
42
src/cli.zig
42
src/cli.zig
@@ -41,12 +41,12 @@ pub const Cli = struct {
|
||||
pub fn startTransform(allocator: *std.mem.Allocator, args: Api.TransformOptions, log: *logger.Log) anyerror!void {}
|
||||
pub fn start(allocator: *std.mem.Allocator, stdout: anytype, stderr: anytype, comptime MainPanicHandler: type) anyerror!void {
|
||||
start_time = std.time.nanoTimestamp();
|
||||
var log = logger.Log.init(allocator);
|
||||
var panicker = MainPanicHandler.init(&log);
|
||||
var log = try allocator.create(logger.Log);
|
||||
log.* = logger.Log.init(allocator);
|
||||
var panicker = MainPanicHandler.init(log);
|
||||
MainPanicHandler.Singleton = &panicker;
|
||||
|
||||
try Command.start(allocator, &log);
|
||||
std.mem.doNotOptimizeAway(&log);
|
||||
try Command.start(allocator, log);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -137,7 +137,7 @@ pub const Arguments = struct {
|
||||
}
|
||||
}
|
||||
|
||||
const ParamType = clap.Param(clap.Help);
|
||||
pub const ParamType = clap.Param(clap.Help);
|
||||
|
||||
const params: [25]ParamType = brk: {
|
||||
@setEvalBranchQuota(9999);
|
||||
@@ -448,6 +448,31 @@ const HelpCommand = struct {
|
||||
}
|
||||
};
|
||||
|
||||
pub const PrintBundleCommand = struct {
|
||||
pub fn exec(ctx: Command.Context) !void {
|
||||
const entry_point = ctx.args.entry_points[0];
|
||||
var out_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
var stdout = std.io.getStdOut();
|
||||
|
||||
var input = try std.fs.openFileAbsolute(try std.os.realpath(ctx.args.entry_points[0], &out_buffer), .{ .read = true });
|
||||
const params = comptime [_]Arguments.ParamType{
|
||||
clap.parseParam("--summary Peek inside the .bun") catch unreachable,
|
||||
};
|
||||
|
||||
var jsBundleArgs = clap.parse(clap.Help, ¶ms, .{ .allocator = ctx.allocator }) catch |err| {
|
||||
try NodeModuleBundle.printBundle(std.fs.File, input, @TypeOf(stdout), stdout);
|
||||
return;
|
||||
};
|
||||
|
||||
if (jsBundleArgs.flag("--summary")) {
|
||||
NodeModuleBundle.printSummaryFromDisk(std.fs.File, input, @TypeOf(stdout), stdout, ctx.allocator) catch {};
|
||||
return;
|
||||
}
|
||||
|
||||
try NodeModuleBundle.printBundle(std.fs.File, input, @TypeOf(stdout), stdout);
|
||||
}
|
||||
};
|
||||
|
||||
pub const Command = struct {
|
||||
pub const Context = struct {
|
||||
start_time: i128,
|
||||
@@ -536,6 +561,13 @@ pub const Command = struct {
|
||||
}
|
||||
};
|
||||
|
||||
if (ctx.args.entry_points.len == 1 and
|
||||
std.mem.endsWith(u8, ctx.args.entry_points[0], ".bun"))
|
||||
{
|
||||
try PrintBundleCommand.exec(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
try BuildCommand.exec(ctx);
|
||||
},
|
||||
else => unreachable,
|
||||
|
||||
@@ -20,5 +20,7 @@ const bundler = @import("../bundler.zig");
|
||||
const NodeModuleBundle = @import("../node_module_bundle.zig").NodeModuleBundle;
|
||||
|
||||
pub const InitCommand = struct {
|
||||
pub fn exec(ctx: Command.Context) !void {}
|
||||
pub fn exec(ctx: Command.Context) !void {
|
||||
Output.prettyErrorln("<r><red>nOt<r> <magenta>iMpLeMeNtEd<r> <yellow>yEt<r>", .{});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -22,5 +22,7 @@ const bundler = @import("../bundler.zig");
|
||||
const NodeModuleBundle = @import("../node_module_bundle.zig").NodeModuleBundle;
|
||||
|
||||
pub const RunCommand = struct {
|
||||
pub fn exec(ctx: Command.Context) !void {}
|
||||
pub fn exec(ctx: Command.Context) !void {
|
||||
Output.prettyErrorln("<r><red>nOt<r> <magenta>iMpLeMeNtEd<r> <yellow>yEt<r>", .{});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -45,7 +45,7 @@ pub const react_specific_warnings = true;
|
||||
// command ../../build/debug/macos-x86_64/bun --use=./nexty2 --new-jsb > /dev/null
|
||||
// end
|
||||
// It only happens 1 out of every N times, probably like 50.
|
||||
pub const parallel_jsb = false;
|
||||
pub const parallel_bun = false;
|
||||
|
||||
pub const CSSModulePolyfill = enum {
|
||||
// When you import a .css file and you reference the import in JavaScript
|
||||
|
||||
@@ -57,6 +57,10 @@ pub const Output = struct {
|
||||
pub var is_stdout_piped = false;
|
||||
pub var is_stderr_piped = false;
|
||||
|
||||
pub inline fn isEmojiEnabled() bool {
|
||||
return enable_ansi_colors and !isWindows;
|
||||
}
|
||||
|
||||
pub fn enableBuffering() void {
|
||||
enable_buffering = true;
|
||||
}
|
||||
|
||||
16
src/http.zig
16
src/http.zig
@@ -1036,12 +1036,19 @@ pub const RequestContext = struct {
|
||||
defer handler.tombstone = true;
|
||||
defer removeWebsocket(handler);
|
||||
defer ctx.arena.deinit();
|
||||
defer ctx.conn.deinit();
|
||||
var is_socket_closed = false;
|
||||
defer {
|
||||
if (!is_socket_closed) {
|
||||
ctx.conn.deinit();
|
||||
}
|
||||
}
|
||||
defer Output.flush();
|
||||
|
||||
handler.checkUpgradeHeaders() catch |err| {
|
||||
switch (err) {
|
||||
error.BadRequest => {
|
||||
defer is_socket_closed = true;
|
||||
|
||||
try ctx.sendBadRequest();
|
||||
},
|
||||
else => {
|
||||
@@ -1059,6 +1066,7 @@ pub const RequestContext = struct {
|
||||
try ctx.writeStatus(426);
|
||||
try ctx.flushHeaders();
|
||||
ctx.done();
|
||||
is_socket_closed = true;
|
||||
return;
|
||||
},
|
||||
}
|
||||
@@ -1103,6 +1111,7 @@ pub const RequestContext = struct {
|
||||
try welcome_message.encode(&writer);
|
||||
if ((try handler.websocket.writeBinary(fbs.getWritten())) == 0) {
|
||||
handler.tombstone = true;
|
||||
is_socket_closed = true;
|
||||
Output.prettyErrorln("<r><red>ERR:<r> <b>Websocket failed to write.<r>", .{});
|
||||
}
|
||||
|
||||
@@ -1111,6 +1120,7 @@ pub const RequestContext = struct {
|
||||
handler.conn.client.getError() catch |err| {
|
||||
Output.prettyErrorln("<r><red>ERR:<r> <b>{s}<r>", .{err});
|
||||
handler.tombstone = true;
|
||||
is_socket_closed = true;
|
||||
};
|
||||
|
||||
var frame = handler.websocket.read() catch |err| {
|
||||
@@ -1118,6 +1128,7 @@ pub const RequestContext = struct {
|
||||
error.ConnectionClosed => {
|
||||
Output.prettyln("Websocket closed.", .{});
|
||||
handler.tombstone = true;
|
||||
is_socket_closed = true;
|
||||
continue;
|
||||
},
|
||||
else => {
|
||||
@@ -1129,6 +1140,7 @@ pub const RequestContext = struct {
|
||||
switch (frame.header.opcode) {
|
||||
.Close => {
|
||||
Output.prettyln("Websocket closed.", .{});
|
||||
is_socket_closed = true;
|
||||
return;
|
||||
},
|
||||
.Text => {
|
||||
@@ -1204,7 +1216,7 @@ pub const RequestContext = struct {
|
||||
}
|
||||
},
|
||||
else => {
|
||||
Output.prettyErrorln("<r>[Websocket]: Unknown cmd: <b>{d}<r>. This might be a version mismatch. Try updating your node_modules.bun", .{@enumToInt(cmd.kind)});
|
||||
Output.prettyErrorln("<r>[Websocket]: Unknown cmd: <b>{d}<r>. This might be a version mismatch. Try updating your node_modules.jsb", .{@enumToInt(cmd.kind)});
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
@@ -6,7 +6,20 @@ const JS = @import("../javascript.zig");
|
||||
const JSBase = @import("../base.zig");
|
||||
const Handler = struct {
|
||||
pub export fn global_signal_handler_fn(sig: i32, info: *const std.os.siginfo_t, ctx_ptr: ?*const c_void) callconv(.C) void {
|
||||
Global.panic("C++ Crash!!", .{});
|
||||
var stdout = std.io.getStdOut();
|
||||
var stderr = std.io.getStdErr();
|
||||
var source = Output.Source.init(stdout, stderr);
|
||||
Output.Source.set(&source);
|
||||
|
||||
if (Output.isEmojiEnabled()) {
|
||||
Output.prettyErrorln("<r><red>Bun will crash now<r> 😭😭😭\n", .{});
|
||||
Output.flush();
|
||||
} else {
|
||||
stderr.writeAll("Bun has crashed :'(\n") catch {};
|
||||
}
|
||||
std.mem.doNotOptimizeAway(source);
|
||||
|
||||
std.os.exit(6);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1101,7 +1101,8 @@ pub const FetchEvent = struct {
|
||||
switch (status) {
|
||||
.Fulfilled => {},
|
||||
else => {
|
||||
this.request_context.sendInternalError(error.rejectedPromise) catch {};
|
||||
VirtualMachine.vm.defaultErrorHandler(resolved.result(VirtualMachine.vm.global.vm()));
|
||||
this.request_context.sendInternalError(error.rejectedPromiseSeeConsole) catch {};
|
||||
return js.JSValueMakeUndefined(ctx);
|
||||
},
|
||||
}
|
||||
|
||||
@@ -195,13 +195,13 @@ pub fn loadRoutes(
|
||||
if (comptime isDebug) {
|
||||
if (comptime is_root) {
|
||||
var i: usize = 0;
|
||||
Output.prettyln("Routes:", .{});
|
||||
Output.prettyErrorln("Routes (last segment only):", .{});
|
||||
while (i < this.routes.routes.len) : (i += 1) {
|
||||
const route = this.routes.routes.get(i);
|
||||
|
||||
Output.prettyln(" {s}: {s}", .{ route.name, route.path });
|
||||
Output.prettyErrorln(" {s}: {s}", .{ route.name, route.path });
|
||||
}
|
||||
Output.prettyln(" {d} routes", .{this.routes.routes.len});
|
||||
Output.prettyErrorln(" {d} routes\n", .{this.routes.routes.len});
|
||||
Output.flush();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user