Compare commits

...

1 Commits

Author SHA1 Message Date
Meghan Denny
91222dba82 fixes 23315 2025-10-06 19:32:20 -07:00
6 changed files with 54 additions and 45 deletions

View File

@@ -1619,19 +1619,27 @@ pub fn spawnMaybeSync(
}
if (subprocess.stdin == .buffer) {
subprocess.stdin.buffer.start().assert();
if (subprocess.stdin.buffer.start().asErr()) |err| {
subprocess.deref();
return globalThis.throwValue(err.toJS(globalThis));
}
}
if (subprocess.stdout == .pipe) {
subprocess.stdout.pipe.start(subprocess, loop).assert();
if (subprocess.stdout.pipe.start(subprocess, loop).asErr()) |err| {
subprocess.deref();
return globalThis.throwValue(err.toJS(globalThis));
}
if ((is_sync or !lazy) and subprocess.stdout == .pipe) {
subprocess.stdout.pipe.readAll();
}
}
if (subprocess.stderr == .pipe) {
subprocess.stderr.pipe.start(subprocess, loop).assert();
if (subprocess.stderr.pipe.start(subprocess, loop).asErr()) |err| {
subprocess.deref();
return globalThis.throwValue(err.toJS(globalThis));
}
if ((is_sync or !lazy) and subprocess.stderr == .pipe) {
subprocess.stderr.pipe.readAll();
}

View File

@@ -85,16 +85,7 @@ pub fn Maybe(comptime ReturnTypeT: type, comptime ErrorTypeT: type) type {
.syscall = .access,
} };
pub fn assert(this: @This()) ReturnType {
switch (this) {
.err => |err| {
bun.Output.panic("Unexpected error\n{}", .{err});
},
.result => |result| return result,
}
}
pub inline fn todo() @This() {
pub fn todo() @This() {
if (Environment.allow_assert) {
if (comptime ReturnType == void) {
@panic("TODO called!");
@@ -123,18 +114,18 @@ pub fn Maybe(comptime ReturnTypeT: type, comptime ErrorTypeT: type) type {
}
/// Unwrap the value if it is `result` or use the provided `default_value`
pub inline fn unwrapOr(this: @This(), default_value: ReturnType) ReturnType {
pub fn unwrapOr(this: @This(), default_value: ReturnType) ReturnType {
return switch (this) {
.result => |v| v,
.err => default_value,
};
}
pub inline fn initErr(e: ErrorType) Maybe(ReturnType, ErrorType) {
pub fn initErr(e: ErrorType) Maybe(ReturnType, ErrorType) {
return .{ .err = e };
}
pub inline fn initErrWithP(e: bun.sys.SystemErrno, syscall: sys.Tag, file_path: anytype) Maybe(ReturnType, ErrorType) {
pub fn initErrWithP(e: bun.sys.SystemErrno, syscall: sys.Tag, file_path: anytype) Maybe(ReturnType, ErrorType) {
return .{ .err = .{
.errno = @intFromEnum(e),
.syscall = syscall,
@@ -142,42 +133,42 @@ pub fn Maybe(comptime ReturnTypeT: type, comptime ErrorTypeT: type) type {
} };
}
pub inline fn asErr(this: *const @This()) ?ErrorType {
pub fn asErr(this: *const @This()) ?ErrorType {
if (this.* == .err) return this.err;
return null;
}
pub inline fn asValue(this: *const @This()) ?ReturnType {
pub fn asValue(this: *const @This()) ?ReturnType {
if (this.* == .result) return this.result;
return null;
}
pub inline fn isOk(this: *const @This()) bool {
pub fn isOk(this: *const @This()) bool {
return switch (this.*) {
.result => true,
.err => false,
};
}
pub inline fn isErr(this: *const @This()) bool {
pub fn isErr(this: *const @This()) bool {
return switch (this.*) {
.result => false,
.err => true,
};
}
pub inline fn initResult(result: ReturnType) Maybe(ReturnType, ErrorType) {
pub fn initResult(result: ReturnType) Maybe(ReturnType, ErrorType) {
return .{ .result = result };
}
pub inline fn mapErr(this: @This(), comptime E: type, err_fn: *const fn (ErrorTypeT) E) Maybe(ReturnType, E) {
pub fn mapErr(this: @This(), comptime E: type, err_fn: *const fn (ErrorTypeT) E) Maybe(ReturnType, E) {
return switch (this) {
.result => |v| .{ .result = v },
.err => |e| .{ .err = err_fn(e) },
};
}
pub inline fn toCssResult(this: @This()) Maybe(ReturnType, bun.css.ParseError(bun.css.ParserError)) {
pub fn toCssResult(this: @This()) Maybe(ReturnType, bun.css.ParseError(bun.css.ParserError)) {
return switch (ErrorTypeT) {
bun.css.BasicParseError => {
return switch (this) {

View File

@@ -110,7 +110,10 @@ pub fn testingImpl(globalThis: *jsc.JSGlobalObject, callframe: *jsc.CallFrame, c
var stylesheet, var extra = ret;
var minify_options: bun.css.MinifyOptions = bun.css.MinifyOptions.default();
minify_options.targets.browsers = browsers;
_ = stylesheet.minify(alloc, minify_options, &extra).assert();
_ = switch (stylesheet.minify(alloc, minify_options, &extra)) {
.err => |err| return err.toJSString(alloc, globalThis),
.result => |result| result,
};
const symbols = bun.ast.Symbol.Map{};
var local_names = bun.css.LocalsResultsMap{};

View File

@@ -167,9 +167,8 @@ pub fn PosixPipeWriter(
}
/// See below for the expected signature of `function_table`. In many cases, the
/// function table can be the same as `Parent`. `anytype` is used because of a
/// dependency loop in Zig.
pub fn PosixBufferedWriter(Parent: type, function_table: anytype) type {
/// function table can be the same as `Parent`.
pub fn PosixBufferedWriter(Parent: type, function_table: type) type {
return struct {
const PosixWriter = @This();
const onWrite: *const fn (*Parent, amount: usize, status: WriteStatus) void = function_table.onWrite;
@@ -373,9 +372,8 @@ pub fn PosixBufferedWriter(Parent: type, function_table: anytype) type {
}
/// See below for the expected signature of `function_table`. In many cases, the
/// function table can be the same as `Parent`. `anytype` is used because of a
/// dependency loop in Zig.
pub fn PosixStreamingWriter(comptime Parent: type, comptime function_table: anytype) type {
/// function table can be the same as `Parent`.
pub fn PosixStreamingWriter(comptime Parent: type, comptime function_table: type) type {
return struct {
const onWrite: fn (*Parent, amount: usize, status: WriteStatus) void = function_table.onWrite;
const onError: fn (*Parent, bun.sys.Error) void = function_table.onError;
@@ -935,9 +933,8 @@ fn BaseWindowsPipeWriter(
}
/// See below for the expected signature of `function_table`. In many cases, the
/// function table can be the same as `Parent`. `anytype` is used because of a
/// dependency loop in Zig.
pub fn WindowsBufferedWriter(Parent: type, function_table: anytype) type {
/// function table can be the same as `Parent`.
pub fn WindowsBufferedWriter(Parent: type, function_table: type) type {
return struct {
source: ?Source = null,
owns_fd: bool = true,
@@ -1206,9 +1203,8 @@ pub const StreamBuffer = struct {
};
/// See below for the expected signature of `function_table`. In many cases, the
/// function table can be the same as `Parent`. `anytype` is used because of a
/// dependency loop in Zig.
pub fn WindowsStreamingWriter(comptime Parent: type, function_table: anytype) type {
/// function table can be the same as `Parent`.
pub fn WindowsStreamingWriter(comptime Parent: type, function_table: type) type {
return struct {
/// reports the amount written and done means that we dont have any
/// other pending data to send (but we may send more data)
@@ -1504,8 +1500,8 @@ pub fn WindowsStreamingWriter(comptime Parent: type, function_table: anytype) ty
};
}
pub const BufferedWriter = if (bun.Environment.isPosix) PosixBufferedWriter else WindowsBufferedWriter;
pub const StreamingWriter = if (bun.Environment.isPosix) PosixStreamingWriter else WindowsStreamingWriter;
pub const BufferedWriter: fn (type, type) type = if (bun.Environment.isPosix) PosixBufferedWriter else WindowsBufferedWriter;
pub const StreamingWriter: fn (type, type) type = if (bun.Environment.isPosix) PosixStreamingWriter else WindowsStreamingWriter;
const std = @import("std");
const Source = @import("./source.zig").Source;

View File

@@ -216,7 +216,10 @@ fn write(this: *IOWriter) enum {
bun.assert(this.writer.handle == .poll);
if (this.writer.handle.poll.isWatching()) return .suspended;
this.writer.start(this.fd, this.flags.pollable).assert();
if (this.writer.start(this.fd, this.flags.pollable).asErr()) |e| {
this.onError(e);
return .failed;
}
return .suspended;
}

View File

@@ -837,7 +837,7 @@ pub const ShellSubprocess = struct {
.result => |result| result,
};
var subprocess = bun.handleOom(event_loop.allocator().create(Subprocess));
var subprocess: *Subprocess = bun.handleOom(event_loop.allocator().create(Subprocess));
out_subproc.* = subprocess;
subprocess.* = Subprocess{
.event_loop = event_loop,
@@ -880,19 +880,27 @@ pub const ShellSubprocess = struct {
}
if (subprocess.stdin == .buffer) {
subprocess.stdin.buffer.start().assert();
switch (subprocess.stdin.buffer.start()) {
.err => |err| return .{ .err = .{ .sys = err.toShellSystemError() } },
.result => |result| result,
}
}
if (subprocess.stdout == .pipe) {
subprocess.stdout.pipe.start(subprocess, event_loop).assert();
switch (subprocess.stdout.pipe.start(subprocess, event_loop)) {
.err => |err| return .{ .err = .{ .sys = err.toShellSystemError() } },
.result => |result| result,
}
if (!spawn_args.lazy and subprocess.stdout == .pipe) {
subprocess.stdout.pipe.readAll();
}
}
if (subprocess.stderr == .pipe) {
subprocess.stderr.pipe.start(subprocess, event_loop).assert();
switch (subprocess.stderr.pipe.start(subprocess, event_loop)) {
.err => |err| return .{ .err = .{ .sys = err.toShellSystemError() } },
.result => |result| result,
}
if (!spawn_args.lazy and subprocess.stderr == .pipe) {
subprocess.stderr.pipe.readAll();
}