Commit 33761ab
committed
Fix JSONDecoder error message for decimal-to-Int conversion (issue #1604)
This commit fixes the regression where JSONDecoder returns incorrect error
information when attempting to decode a decimal value (e.g., 123.45) as Int.
**Root Cause (from git history investigation):**
- Initial implementation (commit 34c45c1, 2023-03-15) had correct error handling
- BufferView refactoring (commit 1ab3832, 2023-04-03) accidentally removed the
proper DecodingError.dataCorrupted throw statements
- This caused JSONError.numberIsNotRepresentableInSwift to be caught at the
top level and converted to a generic error with empty codingPath
**Changes:**
- Restored proper error handling in `_slowpath_unwrapFixedWidthInteger`
- Changed JSONError.numberIsNotRepresentableInSwift throws to
DecodingError.dataCorrupted with correct codingPath and debugDescription
- Added regression test to prevent future breakage
**Before (broken):**
- codingPath: [] (empty)
- debugDescription: "The given data was not valid JSON."
**After (fixed):**
- codingPath: ["foo"]
- debugDescription: "Parsed JSON number <123.45> does not fit in Int."
Fixes #1604
Related: #2741 parent 5f2bbd9 commit 33761ab
File tree
2 files changed
+134
-2
lines changed- Sources/FoundationEssentials/JSON
- Tests/FoundationEssentialsTests
2 files changed
+134
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1000 | 1000 | | |
1001 | 1001 | | |
1002 | 1002 | | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
1003 | 1019 | | |
1004 | 1020 | | |
1005 | 1021 | | |
1006 | 1022 | | |
1007 | 1023 | | |
1008 | 1024 | | |
1009 | | - | |
| 1025 | + | |
1010 | 1026 | | |
1011 | 1027 | | |
1012 | 1028 | | |
| |||
1021 | 1037 | | |
1022 | 1038 | | |
1023 | 1039 | | |
1024 | | - | |
| 1040 | + | |
1025 | 1041 | | |
1026 | 1042 | | |
1027 | 1043 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
901 | 901 | | |
902 | 902 | | |
903 | 903 | | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
904 | 1020 | | |
905 | 1021 | | |
906 | 1022 | | |
| |||
0 commit comments