Skip to content

[charon-ml] LLBC loader uses both result and exception #1287

Description

@niooss-ledger

Hello,

Function crate_of_json_file is declared to return a result but may also throw some exceptions, in

let crate_of_json_file (file : string) : (crate, string) result =
let* format = OfPostcardBasic.format_hint_of_file file in
match format with
| Json ->
let json = Yojson.Basic.from_file file in
crate_of_json json

For example when using a malformed JSON file, Aeneas displays the raw exception with a stack trace:

$ echo '{' > /tmp/invalid.llbc
$ aeneas -backend lean /tmp/invalid.llbc 
Uncaught exception:
  
  Yojson__Common.Json_error("Line 2, bytes -1-0:\nUnexpected end of input")

Raised at Yojson__Common.json_error in file "lib/common.ml", line 5, characters 19-39
Called from Yojson__Basic.__ocaml_lex_read_json_rec in file "lib/read.mll", line 215, characters 38-57
Called from Yojson__Basic.read_json in file "lib/read.ml" (inlined), line 980, characters 3-39
Called from Yojson__Basic.from_lexbuf in file "lib/read.mll", line 875, characters 8-26
Called from Yojson__Basic.from_channel in file "lib/read.mll", line 896, characters 6-26
Called from Yojson__Basic.from_file in file "lib/read.mll", line 903, characters 14-47
Re-raised at Yojson__Basic.from_file in file "lib/read.mll", line 908, characters 6-13
Called from Charon__OfJson.crate_of_json_file in file "charon/charon-ml/src/OfJson.ml", line 59, characters 17-44
Called from Dune__exe__Main in file "Main.ml", line 557, characters 8-35

Are you interested in this kind of inconsistencies in the OCaml API? There are other occurences of similar patterns, for example when char_of_json calls String.get_utf_8_uchar.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions