Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements around external modules and error handling #605

Merged
merged 4 commits into from
Apr 16, 2024

Commits on Apr 13, 2024

  1. Fix: allow external modules to access the OCaml stdlib

    This would deserve a further look into it, but for now it's impeding development
    without providing any meaningful security.
    AltGr committed Apr 13, 2024
    Configuration menu
    Copy the full SHA
    c8e529d View commit details
    Browse the repository at this point in the history

Commits on Apr 15, 2024

  1. OCaml runtime: register fallback exception printers

    This was a pending TODO: now the Catala program compiled into OCaml should
    return better messages and a little more information about uncaught exceptions.
    
    Note that this also concerns, at the moment, compiled modules called from the
    Catala interpreter: in this case, it's already better than nothing, but what we
    need is proper interoperation between the runtime exceptions and the interpreter
    handling (`EmptyError` should already be handled properly since it is critical
    to the computation flow, but "error" exceptions are left uncaught and will kill
    the interpreter).
    
    This may be part of a bigger task on unifying the output of the runtime and
    toplevel, which also concerns computation traces.
    
    Note 2: All runtime exceptions don't have a position available, which is quite
    unfortunate when your program hits an error. With `OCAMLRUNPARAM=b` and if
    compiled with `-g` (which should normally be the case), you can get an OCaml
    backtrace but that's not very friendly. Ideas for improvement:
    - The runtime could force-enable backtrace recording (`Printexc.record_backtrace
      true`) to supersede the need for `OCAMLRUNPARAM`. We can also record our own
      handler to print the file position and/or backtrace in the way we see fit
    - The printer of OCaml code in Catala could insert line directives so that the
      positions in the backtrace actually trace automatically back to the Catala
      code
    - If we don't want to leverage any OCaml machinery in this way, the compiler
      should add position information to any operator that might fail (e.g.
      divisions, date comparisons, etc.).
    Note that running in trace mode might already help pinpoint the location of the
    error ?
    AltGr committed Apr 15, 2024
    Configuration menu
    Copy the full SHA
    5d432d6 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    20288bc View commit details
    Browse the repository at this point in the history
  3. Preserve the capitalisation of module filenames

    Module names must be capitalised (start with a capital letter), and the name of
    the file on disk must match ; however, matching up to capitalisation is allowed,
    i.e. the file on disk can start with a lowercase letter.
    
    A mismatch between Clerk assuming generated module artifacts would match the
    capitalised module name, and `catala depends` matching the names of files on
    disk (because it would otherwise mean treating dependencies differently
    depending on if they originate from modules or not) was causing "file not found"
    errors later on in the compilation chain.
    
    This patch enforces that the capitalisation of the original file name on
    disk (which is always known) takes precedence in Clerk, matching the behaviour
    of `catala depends` and fixing the issue. It's also actually a small
    simplification in Clerk code.
    AltGr committed Apr 15, 2024
    Configuration menu
    Copy the full SHA
    1de18f0 View commit details
    Browse the repository at this point in the history