[][src]Module lisbeth_error::reporter

Allows to report errors to the user.

This module contains the ErrorReporter structure, which holds metadata about the input. This structure provides the metadata that are needed to properly report the error to the user.

Example

The following code snippet shows how objects defined in the lisbeth_error crate interact with each other:

use lisbeth_error::{
    error::AnnotatedError,
    reporter::ErrorReporter,
};


let reporter = ErrorReporter::input_file(
    "docs.txt".to_string(),
    "The cat are on the table.".to_string(),
);
let file = reporter.spanned_str();

let cat = file.split_at(4).1.split_at(3).0;
let are = file.split_at(8).1.split_at(3).0;

let report = AnnotatedError::new(are.span(), "Conjugation error")
    .with_annotation(cat.span(), "`cat` is singular,")
    .with_annotation(are.span(), "but `are` is used only for plural subject");

println!("{}", reporter.format_error(&report));

This will print to STDOUT:

Error: Conjugation error
--> docs.txt:1:9
    |
  1 |                                           The cat are on the table.
    |                                               ^^^ ^^^
    | `cat` is singular,----------------------------'   |
    | but `are` is used only for plural subject---------'
    |

Structs

ErrorReporter

Holds metadata about the input, allows to report errors to the user.

FormattedError

An error object that can finally be displayed.