pub struct Handler {
    pub flags: HandlerFlags,
    /* private fields */
}
Expand description

A handler deals with errors; certain errors (fatal, bug, unimpl) may cause immediate exit, others log errors for later reporting.

Example

swc provides a global-like variable (HANDLER) of type Handler that can be used to report errors.

You can refer to the lint rules for other example usages. All lint rules have code for error reporting.

Error reporting in swc

use swc_common::errors::HANDLER;

    HANDLER.with(|handler| {
        // You can access the handler for the current file using HANDLER.with.

        // We now report an error

        // `struct_span_err` creates a builder for a diagnostic.
        // The span passed to `struct_span_err` will used to point the problematic code.
        //
        // You may provide additional information, like a previous declaration of parameter.
        handler
            .struct_span_err(
                span,
                &format!("`{}` used as parameter more than once", js_word),
            )
            .span_note(
                old_span,
                &format!("previous definition of `{}` here", js_word),
            )
            .emit();
    });

Fields

flags: HandlerFlags

Implementations

This is supported on crate feature tty-emitter only.
This is supported on crate feature tty-emitter only.

Example implementation of Emitter is EmitterWriter

Resets the diagnostic error count as well as the cached emitted diagnostics.

NOTE: DO NOT call this function from rustc. It is only meant to be called from external tools that want to reuse a Parser cleaning the previously emitted diagnostics as well as the overall count of emitted error diagnostics.

true if we haven’t taught a diagnostic with this code already. The caller must then teach the user about such a diagnostic.

Used to suppress emitting the same error multiple times with extended explanation when calling -Z teach.

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

The archived version of the pointer metadata for this type.

Converts some archived metadata to the pointer metadata for itself.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Deserializes using the given deserializer

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type for metadata in pointers and references to Self.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more