diff options
author | mrkutly <mark.sauer.utley@gmail.com> | 2022-06-09 21:45:48 -0400 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-06-11 18:39:10 +0100 |
commit | d91c49ac13e55b769d553a97b59727ebbc6ea071 (patch) | |
tree | a103ba30e13fc259c52f17ed586d6819f83c79dc /src | |
parent | 7311f679f7b5def0b79a9c61ba506fa37dc14bb2 (diff) | |
download | gleam_json-d91c49ac13e55b769d553a97b59727ebbc6ea071.tar.gz gleam_json-d91c49ac13e55b769d553a97b59727ebbc6ea071.zip |
add tests for runtime decode errors
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam_json_ffi.mjs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/gleam_json_ffi.mjs b/src/gleam_json_ffi.mjs index 115c503..b60d848 100644 --- a/src/gleam_json_ffi.mjs +++ b/src/gleam_json_ffi.mjs @@ -36,7 +36,7 @@ export function decode(string) { } } -function getJsonDecodeError(stdErr, json) { +export function getJsonDecodeError(stdErr, json) { if (isUnexpectedEndOfInput(stdErr)) return new UnexpectedEndOfInput() const unexpectedByteRuntime = getUnexpectedByteRuntime(stdErr) if (unexpectedByteRuntime) return toUnexpectedByteError(unexpectedByteRuntime, stdErr, json) @@ -88,7 +88,7 @@ const chromiumUnexpectedByteRegex = /unexpected token (.) in JSON at position (\ * * JavascriptCore only reports what the character is and not its position. */ -const jsCoreUnexpectedByteRegex = /unexpected identifier "(.)"/i +const jsCoreUnexpectedByteRegex = /unexpected (identifier|token) "(.)"/i /** * Matches unexpected byte messages in: @@ -96,7 +96,7 @@ const jsCoreUnexpectedByteRegex = /unexpected identifier "(.)"/i * * Matches the position in a 2d grid only and not the character. */ -const spidermonkeyUnexpectedByteRegex = /(unexpected character|expected double-quoted property name) at line (\d+) column (\d+)/i +const spidermonkeyUnexpectedByteRegex = /(unexpected character|expected .*) at line (\d+) column (\d+)/i function getUnexpectedByteRuntime(err) { if (chromiumUnexpectedByteRegex.test(err.message)) return Runtime.chromium @@ -151,7 +151,7 @@ function toSpidermonkeyUnexpectedByteError(err, json) { function toJsCoreUnexpectedByteError(err) { const match = jsCoreUnexpectedByteRegex.exec(err.message) - const byte = toHex(match[1]) + const byte = toHex(match[2]) return new UnexpectedByte(byte, 0) } |