@@ -317,39 +317,29 @@ module CompileFail = {
317
317
let decode = (json ): t => {
318
318
open JSON
319
319
switch json {
320
- | Object (dict {"type" : String (type_ )}) =>
321
- switch type_ {
322
- | "syntax_error" =>
323
- let locMsgs = switch json {
324
- | Object (dict {"errors" : Array (errors )}) => errors -> Array .map (LocMsg .decode )
325
- | _ => throw (Failure (` Failed to decode errors from syntax_error. ${__LOC__}` ))
326
- }
327
- // TODO: There seems to be a bug in the ReScript bundle that reports
328
- // back multiple LocMsgs of the same value
329
- locMsgs -> LocMsg .dedupe -> SyntaxErr
330
- | "type_error" =>
331
- let locMsgs = switch json {
332
- | Object (dict {"errors" : Array (errors )}) => errors -> Array .map (LocMsg .decode )
333
- | _ => throw (Failure (` Failed to decode errors from type_error. ${__LOC__}` ))
334
- }
335
- TypecheckErr (locMsgs )
336
- | "warning_error" =>
337
- let warnings = switch json {
338
- | Object (dict {"errors" : Array (warnings )}) => warnings -> Array .map (Warning .decode )
339
- | _ => throw (Failure (` Failed to decode errors from warning_error. ${__LOC__}` ))
340
- }
341
- WarningErr (warnings )
342
- | "other_error" =>
343
- let locMsgs = switch json {
344
- | Object (dict {"errors" : Array (errors )}) => errors -> Array .map (LocMsg .decode )
345
- | _ => throw (Failure (` Failed to decode errors from other_error. ${__LOC__}` ))
346
- }
347
- OtherErr (locMsgs )
348
-
349
- | "warning_flag_error" => WarningFlagErr (WarningFlag .decode (json ))
350
- | other => throw (Failure (` Unknown type "${other}" in CompileFail result. ${__LOC__}` ))
351
- }
352
- | _ => throw (Failure (` Failed to decode CompileFail. ${__LOC__}` ))
320
+ | Object (dict {"type" : String ("syntax_error" ), "errors" : Array (errors )}) =>
321
+ let locMsgs = errors -> Array .map (LocMsg .decode )
322
+ // TODO: There seems to be a bug in the ReScript bundle that reports
323
+ // back multiple LocMsgs of the same value
324
+ locMsgs -> LocMsg .dedupe -> SyntaxErr
325
+ | Object (dict {"type" : String ("type_error" ), "errors" : Array (errors )}) =>
326
+ let locMsgs = errors -> Array .map (LocMsg .decode )
327
+ TypecheckErr (locMsgs )
328
+ | Object (dict {"type" : String ("warning_error" ), "errors" : Array (warnings )}) =>
329
+ let warnings = warnings -> Array .map (Warning .decode )
330
+ WarningErr (warnings )
331
+ | Object (dict {"type" : String ("other_error" ), "errors" : Array (errors )}) =>
332
+ let locMsgs = errors -> Array .map (LocMsg .decode )
333
+ OtherErr (locMsgs )
334
+ | Object (dict {"type" : String ("warning_flag_error" )}) => WarningFlagErr (WarningFlag .decode (json ))
335
+ | Object (dict {"type" : String (other )}) =>
336
+ throw (Failure (` Unknown type "${other}" in CompileFail result. ${__LOC__}` ))
337
+ | _ =>
338
+ throw (
339
+ Failure (
340
+ ` Failed to decode CompileFail. ${__LOC__}. Could not decode \` ${json-> JSON.stringify}\` ` ,
341
+ ),
342
+ )
353
343
}
354
344
}
355
345
}
@@ -365,16 +355,9 @@ module CompilationResult = {
365
355
let decode = (~time : float , json : JSON .t ): t => {
366
356
open JSON
367
357
switch json {
368
- | Object (dict {"type" : String (type_ )}) =>
369
- switch type_ {
370
- | "success" => Success (CompileSuccess .decode (~time , json ))
371
- | "unexpected_error" =>
372
- switch json {
373
- | Object (dict {"msg" : String (msg )}) => UnexpectedError (msg )
374
- | _ => throw (Failure (` Failed to decode msg from unexpected_error. ${__LOC__}` ))
375
- }
376
- | _ => Fail (CompileFail .decode (json ))
377
- }
358
+ | Object (dict {"type" : String ("success" )}) => Success (CompileSuccess .decode (~time , json ))
359
+ | Object (dict {"type" : String ("unexpected_error" ), "msg" : String (msg )}) => UnexpectedError (msg )
360
+ | Object (dict {"type" : String (_ )}) => Fail (CompileFail .decode (json ))
378
361
| _ => throw (Failure (` Failed to decode CompilationResult. ${__LOC__}` ))
379
362
}
380
363
}
@@ -390,20 +373,19 @@ module ConversionResult = {
390
373
let decode = (~fromLang : Lang .t , ~toLang : Lang .t , json ): t => {
391
374
open JSON
392
375
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__}` ))
376
+ | Object (dict {"type" : String ("success" )}) => Success (ConvertSuccess .decode (json ))
377
+ | Object (dict {"type" : String ("unexpected_error" ), "msg" : String (msg )}) => UnexpectedError (msg )
378
+ | Object (dict {"type" : String ("syntax_error" ), "errors" : Array (errors )}) =>
379
+ let locMsgs = errors -> Array .map (LocMsg .decode )
380
+ Fail ({fromLang , toLang , details : locMsgs })
381
+ | Object (dict {"type" : String (other )}) =>
382
+ Unknown (` Unknown conversion result type "${other}"` , json )
383
+ | _ =>
384
+ throw (
385
+ Failure (
386
+ ` Failed to decode ConversionResult. ${__LOC__}. Could not decode \` ${json-> JSON.stringify}\` ` ,
387
+ ),
388
+ )
407
389
}
408
390
}
409
391
}
0 commit comments