[][src]Crate lark_error

Types for tracking errors through queries.

Here is how it works:

  • Queries that can themselves report errors return WithError<T>; the errors contained in that value were discovered during executing that query.
  • If another query uses the result of a query that returns WithError, it can just use into_value to ignore the errors -- WithError always includes some form of sentinel value that you can use (i.e., you can just ignore the errors and try to get on with life).
  • In the worst case, one can you Result<T, ErrorReported> and have Err(ErrorReported) act as a sentintel value for "failed to produce a value because of some error". This is not preferred because now downstream queries have to care whether you propagated an error or not, but sometimes it's the best/easiest thing to do.
    • To help with this, the or_sentinel! query acts as a kind of ? operator for bridging a Result<T, ErrorReported> into a U where U has a proper sentinel -- if the result is Err(ErrorReported), it creates the error-sentinel for U and returns it.
    • This relies on the ErrorSentinel trait, which defines the error-sentinel for a given type.

This scheme is not the most ergonomic and I would like to change it, but it will do for now. -nikomatsakis

Macros

or_return_sentinel

A kind of ? operator for Result<T, ErrorReported> values -- if $v is an Err, then returns WithError::error_sentinel($cx) from the surrounding function.

Structs

Diagnostic

A span with an associated label. TODO: We may want to merge this with what's available in error reporting

ErrorReported

Unit type used in Result to indicate a value derived from other value where an error was already reported. The span is "some span" from one of the errors.

WithError

Used to indicate an operation that may report an error. Note that there is a subtle -- but important! -- difference between ErrorReported and this type -- returning Err(ErrorReported) indicates that the query invoked some other operation which failed. Returning WithError<X> (where error is Some) indicates that the operation itself is reporting the error. Confusing the two will result in too many or too few error reports being shown to the user.

Traits

ErrorSentinel
ResultExt