Skip to content

Error reporting system #83

@ptal

Description

@ptal

Instead of building errors in different way and everywhere in the code, we take the approach of implementing a file error.rs in each module (such as more or less done in rustc). We use an error enum such as:

enum TypingError {
  TypeMismatch(TypeMismatchInfo),
  ...
}

struct TypeMismatchInfo {
  span: Span;
  ...
}

Each error has a struct containing the relevant information for later printing the error. An error enum must implement a trait to retrieve an error code:

trait ErrorCode {
  fn error_code(&self) -> String;
}

That returns the name of the variant, here TypeMismatch. It is used in the error attribute #29.

Each error structure must implement a trait for printing the error:

trait DisplayError {
  fn display_error(&self, cx: &ExtCtxt);
}

This is flexible enough to allow different kind of printing, even for a JSON output or for deep explanation (as with --explain in rustc).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions