Skip to content

Commit 5446eab

Browse files
authored
Add more context to malformed JSON errors (#429)
Include the JSON text and underlying error.
1 parent c110bd1 commit 5446eab

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: Sources/TSCBasic/JSON.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ import Foundation
171171

172172
enum JSONDecodingError: Error {
173173
/// The input byte string is malformed.
174-
case malformed
174+
case malformed(json: String, underlyingError: Error)
175175
}
176176

177177
extension JSONDecodingError: CustomNSError {
@@ -262,7 +262,7 @@ extension JSON {
262262
// times.
263263
self = JSON.convertToJSON(result)
264264
} catch {
265-
throw JSONDecodingError.malformed
265+
throw JSONDecodingError.malformed(json: String(data: data, encoding: .utf8) ?? data.description, underlyingError: error)
266266
}
267267
}
268268

0 commit comments

Comments
 (0)