From d91c49ac13e55b769d553a97b59727ebbc6ea071 Mon Sep 17 00:00:00 2001 From: mrkutly Date: Thu, 9 Jun 2022 21:45:48 -0400 Subject: add tests for runtime decode errors --- src/gleam_json_ffi.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') 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) } -- cgit v1.2.3