Skip to content

Commit

Permalink
deduplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed Dec 21, 2024
1 parent f0345a1 commit 739b971
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
24 changes: 6 additions & 18 deletions src/bun.js/webcore/blob.zig
Original file line number Diff line number Diff line change
Expand Up @@ -910,9 +910,7 @@ pub const Blob = struct {
switch (result) {
.success => this.promise.resolve(globalObject, JSC.jsNumber(0)),
.failure => |err| {
const js_err = globalObject.createErrorInstance("{s}", .{err.message});
js_err.put(globalObject, JSC.ZigString.static("code"), JSC.ZigString.init(err.code).toJS(globalObject));
this.promise.rejectOnNextTick(globalObject, js_err);
this.promise.rejectOnNextTick(globalObject, err.toJS(globalObject));
},
}
}
Expand Down Expand Up @@ -1061,9 +1059,7 @@ pub const Blob = struct {
switch (result) {
.success => this.promise.resolve(globalObject, JSC.jsNumber(this.store.data.bytes.len)),
.failure => |err| {
const js_err = globalObject.createErrorInstance("{s}", .{err.message});
js_err.put(globalObject, JSC.ZigString.static("code"), JSC.ZigString.init(err.code).toJS(globalObject));
this.promise.rejectOnNextTick(globalObject, js_err);
this.promise.rejectOnNextTick(globalObject, err.toJS(globalObject));
},
}
}
Expand Down Expand Up @@ -3676,9 +3672,7 @@ pub const Blob = struct {
self.promise.reject(globalObject, js_err);
},
.failure => |err| {
const js_err = globalObject.createErrorInstance("{s}", .{err.message});
js_err.put(globalObject, ZigString.static("code"), ZigString.init(err.code).toJS(globalObject));
self.promise.rejectOnNextTick(globalObject, js_err);
self.promise.rejectOnNextTick(globalObject, err.toJS(globalObject));
},
}
}
Expand Down Expand Up @@ -4018,9 +4012,7 @@ pub const Blob = struct {
this.promise.reject(this.globalThis, js_err);
},
.failure => |err| {
const js_err = this.globalThis.createErrorInstance("{s}", .{err.message});
js_err.put(this.globalThis, ZigString.static("code"), ZigString.init(err.code).toJS(this.globalThis));
this.promise.rejectOnNextTick(this.globalThis, js_err);
this.promise.rejectOnNextTick(this.globalThis, err.toJS(this.globalThis));
},
}
}
Expand Down Expand Up @@ -4082,9 +4074,7 @@ pub const Blob = struct {
this.promise.resolve(globalThis, .true);
},
.failure => |err| {
const js_err = globalThis.createErrorInstance("{s}", .{err.message});
js_err.put(globalThis, ZigString.static("code"), ZigString.init(err.code).toJS(globalThis));
this.promise.rejectOnNextTick(globalThis, js_err);
this.promise.rejectOnNextTick(globalThis, err.toJS(globalThis));
},
}
}
Expand All @@ -4103,9 +4093,7 @@ pub const Blob = struct {
this.promise.resolve(globalThis, JSValue.jsNumber(stat.size));
},
.failure => |err| {
const js_err = globalThis.createErrorInstance("{s}", .{err.message});
js_err.put(globalThis, ZigString.static("code"), ZigString.init(err.code).toJS(globalThis));
this.promise.rejectOnNextTick(globalThis, js_err);
this.promise.rejectOnNextTick(globalThis, err.toJS(globalThis));
},
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/s3.zig
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ pub const AWSCredentials = struct {
pub const S3Error = struct {
code: []const u8,
message: []const u8,

pub fn toJS(err: *const @This(), globalObject: *JSC.JSGlobalObject) JSC.JSValue {
const js_err = globalObject.createErrorInstance("{s}", .{err.message});
js_err.put(globalObject, JSC.ZigString.static("code"), JSC.ZigString.init(err.code).toJS(globalObject));
return js_err;
}
};
pub const S3StatResult = union(enum) {
success: struct {
Expand Down Expand Up @@ -1147,11 +1153,9 @@ pub const AWSCredentials = struct {
if (readable.ptr == .Bytes) {
const globalThis = this.readable_stream_ref.globalThis().?;
if (request_err) |err| {
const js_err = globalThis.createErrorInstance("{s}", .{err.message});
js_err.put(globalThis, JSC.ZigString.static("code"), JSC.ZigString.init(err.code).toJS(globalThis));
readable.ptr.Bytes.onData(
.{
.err = .{ .JSValue = js_err },
.err = .{ .JSValue = err.toJS(globalThis) },
},
bun.default_allocator,
);
Expand Down Expand Up @@ -1221,9 +1225,7 @@ pub const AWSCredentials = struct {
sink.abort();
return;
}
const js_err = globalObject.createErrorInstance("{s}", .{err.message});
js_err.put(globalObject, JSC.ZigString.static("code"), JSC.ZigString.init(err.code).toJS(globalObject));
sink.endPromise.rejectOnNextTick(globalObject, js_err);
sink.endPromise.rejectOnNextTick(globalObject, err.toJS(globalObject));
},
}
}
Expand Down Expand Up @@ -1406,9 +1408,7 @@ pub const AWSCredentials = struct {
sink.abort();
return;
}
const js_err = globalObject.createErrorInstance("{s}", .{err.message});
js_err.put(globalObject, JSC.ZigString.static("code"), JSC.ZigString.init(err.code).toJS(globalObject));
sink.endPromise.rejectOnNextTick(globalObject, js_err);
sink.endPromise.rejectOnNextTick(globalObject, err.toJS(globalObject));
},
}
}
Expand Down

0 comments on commit 739b971

Please sign in to comment.