Skip to content

Commit 7c6f981

Browse files
committed
fix decoding of converson result
1 parent fc481f2 commit 7c6f981

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/bindings/RescriptCompilerApi.res

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -390,20 +390,19 @@ module ConversionResult = {
390390
let decode = (~fromLang: Lang.t, ~toLang: Lang.t, json): t => {
391391
open JSON
392392
switch json {
393-
| Object(dict{
394-
"type": String(type_),
395-
"msg": ?Some(String(msg)),
396-
"errors": ?Some(Array(errors)),
397-
}) =>
398-
switch type_ {
399-
| "success" => Success(ConvertSuccess.decode(json))
400-
| "unexpected_error" => msg->UnexpectedError
401-
| "syntax_error" =>
402-
let locMsgs = errors->Array.map(LocMsg.decode)
403-
Fail({fromLang, toLang, details: locMsgs})
404-
| other => Unknown(`Unknown conversion result type "${other}"`, json)
405-
}
406-
| _ => throw(Failure(`Failed to decode ConversionResult. ${__LOC__}`))
393+
| Object(dict{"type": String("success")}) => Success(ConvertSuccess.decode(json))
394+
| Object(dict{"type": String("unexpected_error"), "msg": String(msg)}) => UnexpectedError(msg)
395+
| Object(dict{"type": String("syntax_error"), "errors": Array(errors)}) =>
396+
let locMsgs = errors->Array.map(LocMsg.decode)
397+
Fail({fromLang, toLang, details: locMsgs})
398+
| Object(dict{"type": String(other)}) =>
399+
Unknown(`Unknown conversion result type "${other}"`, json)
400+
| _ =>
401+
throw(
402+
Failure(
403+
`Failed to decode ConversionResult. ${__LOC__}. Could not decode \`${json->JSON.stringify}\``,
404+
),
405+
)
407406
}
408407
}
409408
}

0 commit comments

Comments
 (0)