Trait wright::errors::Error [] [src]

pub trait Error<'source>: Debug + Sized {
    fn get_name(&self) -> &str;
fn get_module(&self) -> &str;
fn get_level(&self) -> ErrorLevel;
fn get_spans(&self) -> &Vec<Span>;
fn get_info(&self) -> &Vec<&str>;
fn get_lines(&self) -> &'source Vec<&'source str>; fn validate(&self) -> Result<(), ()> { ... }
fn get_displayable(&self) -> ErrorToDisplay<'source> { ... }
fn display(&self) { ... } }

Trait for Errors. Any error used throughout the wright compiler/interpreter must implement this trait for consistency.

Required Methods

Return the name of the error.

Return the module or location the error came from.

Returns the error level.

Returns a vector of the content spans of the offending content.

If there are no spans (the vector is empty) then line numbers will not be used in error reporting. (The entire source will be printed.)

Spans must be single line only. (The error is invalid otherwise.)

Return information about the error.

The first entry is displayed as the error information at the top of the error and the following ones are displayed next to the the underlining string for each span.

Any additional information (past the appropriate number for the given set of spans) will not show up in the error report.

If the vector is empty or too short then each informative will default to an empty string except for the first one, which defaults to "An error occurred."

Return a reference to the source code of the module (file) containing the error. Or the source of the error if it was not in code.

If line numbers are not being used, the full source returned by this function will be printed.

The error will be invalid if the source is not long enough to contain the errors found.

Provided Methods

Check to see if the error is valid. (Checks to make sure there are the appropriate numbers of spans, informatics, and source lines).

Errors

  • If any of the spans from get_spans are multiple lines.
  • If any of the spans are outside of the of the source module/file.

Turn error into one which can be displayed. (ErrorToDisplay implements fmt::Display)

Panics

Panics if validate() returns an Err().

Displays a given error via the get_displayable method.

Panics

Panics if validate() returns and Err().

Implementors