Skip to content

Commit 8c399ad

Browse files
committed
Fix JSError recursion in some cases
1 parent 472132f commit 8c399ad

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Sources/JavaScript/JSError.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ public struct JSError: Error, CustomStringConvertible {
2020
init(context: JSContextRef, pointer: JSValueRef) {
2121
let value = JSValue(context: context, pointer: pointer)
2222
do {
23-
self.description = try value.toString()
23+
guard value.isObject else {
24+
description = "not an object"
25+
return
26+
}
27+
guard let message = value["message"] else {
28+
self.description = "failed to access error.message"
29+
return
30+
}
31+
self.description = try message.toString()
2432
} catch {
25-
self.description = "\(error)"
33+
self.description = "failed to convert JSError"
2634
}
2735
}
2836
}

0 commit comments

Comments
 (0)