Skip to content

Commit 2fd00d3

Browse files
committed
V8 errors msg as zig error enum
1 parent fd10baf commit 2fd00d3

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/v8.zig

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,7 +2720,7 @@ pub const InspectorSession = struct {
27202720
return RemoteObject{ .handle = remote_object };
27212721
}
27222722

2723-
pub fn unwrapObject(self: InspectorSession, allocator: std.mem.Allocator, objectId: []const u8) !UnwrapResult {
2723+
pub fn unwrapObject(self: InspectorSession, allocator: std.mem.Allocator, objectId: []const u8) !UnwrappedObject {
27242724
const in_objectId = c.CZigString{
27252725
.ptr = objectId.ptr,
27262726
.len = objectId.len,
@@ -2740,15 +2740,18 @@ pub const InspectorSession = struct {
27402740
&out_objectGroup,
27412741
);
27422742
if (!result) {
2743-
return .{ .err = CZigStringToString(out_error) };
2743+
if (CZigStringToString(out_error)) |err| {
2744+
if (std.mem.eql(u8, err, "Invalid remote object id")) return error.InvalidRemoteObjectId;
2745+
if (std.mem.eql(u8, err, "Cannot find context with specified id")) return error.CannotFindContextWithSpecifiedId;
2746+
if (std.mem.eql(u8, err, "Could not find object with given id")) return error.CouldNotFindObjectWithGivenId;
2747+
return error.NewUnwrapErrorPleaseReport;
2748+
}
2749+
return error.V8AllocFailed;
27442750
}
2745-
27462751
return .{
2747-
.ok = .{
2748-
.value = Value{ .handle = out_value_handle.? },
2749-
.context = Context{ .handle = out_context_handle.? },
2750-
.objectGroup = CZigStringToString(out_objectGroup),
2751-
},
2752+
.value = Value{ .handle = out_value_handle.? },
2753+
.context = Context{ .handle = out_context_handle.? },
2754+
.objectGroup = CZigStringToString(out_objectGroup),
27522755
};
27532756
}
27542757
};
@@ -2762,11 +2765,6 @@ pub const UnwrappedObject = struct {
27622765
context: Context,
27632766
objectGroup: ?[]const u8,
27642767
};
2765-
pub const UnwrapResultEnum = enum { ok, err };
2766-
pub const UnwrapResult = union(UnwrapResultEnum) {
2767-
ok: UnwrappedObject,
2768-
err: ?[]const u8,
2769-
};
27702768

27712769
/// Note: Some getters return owned memory (strings), while others return memory owned by V8 (objects).
27722770
/// The getters short-circuit if the default values is not available as converting the defaults to V8 causes unnecessary overhead.

0 commit comments

Comments
 (0)