Skip to content

Commit f082553

Browse files
committed
Improve the error messages
1 parent bc0448d commit f082553

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

Foundation/NSJSONSerialization.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -540,12 +540,12 @@ private struct JSONReader {
540540
}
541541
guard let separatorIndex = try consumeStructure(Structure.NameSeparator, input: index) else {
542542
throw NSError(domain: NSCocoaErrorDomain, code: NSCocoaError.PropertyListReadCorruptError.rawValue, userInfo: [
543-
"NSDebugDescription" : "Invalid value at location \(source.distanceFromStart(input))"
543+
"NSDebugDescription" : "Invalid separator at location \(source.distanceFromStart(index))"
544544
])
545545
}
546546
guard let (value, finalIndex) = try parseValue(separatorIndex) else {
547547
throw NSError(domain: NSCocoaErrorDomain, code: NSCocoaError.PropertyListReadCorruptError.rawValue, userInfo: [
548-
"NSDebugDescription" : "Invalid value at location \(source.distanceFromStart(input))"
548+
"NSDebugDescription" : "Invalid value at location \(source.distanceFromStart(separatorIndex))"
549549
])
550550
}
551551

@@ -574,14 +574,9 @@ private struct JSONReader {
574574
index = nextIndex
575575
continue
576576
}
577-
else {
578-
throw NSError(domain: NSCocoaErrorDomain, code: NSCocoaError.PropertyListReadCorruptError.rawValue, userInfo: [
579-
"NSDebugDescription" : "Unexpected end of file while parsing array at location \(source.distanceFromStart(input))"
580-
])
581-
}
582577
}
583578
throw NSError(domain: NSCocoaErrorDomain, code: NSCocoaError.PropertyListReadCorruptError.rawValue, userInfo: [
584-
"NSDebugDescription" : "Unexpected end of file while parsing array at location \(source.distanceFromStart(input))"
579+
"NSDebugDescription" : "Badly formed array at location \(source.distanceFromStart(index))"
585580
])
586581
}
587582
}

0 commit comments

Comments
 (0)