Crate oxc_diagnostics

Crate oxc_diagnostics 

Source
Expand description

Error data types and utilities for handling/reporting them.

The main type in this module is OxcDiagnostic, which is used by all other oxc tools to report problems. It implements miette’s Diagnostic trait, making it compatible with other tooling you may be using.

use oxc_diagnostics::{OxcDiagnostic, Result};
fn my_tool() -> Result<()> {
    try_something().map_err(|e| OxcDiagnostic::error(e.to_string()))?;
    Ok(())
}

See the miette documentation for more information on how to interact with diagnostics.

§Reporting

If you are writing your own tools that may produce their own errors, you can use DiagnosticService to format and render them to a string or a stream. It can receive Errors over a multi-producer, single consumer

use std::{path::PathBuf, sync::Arc, thread};
use oxc_diagnostics::{DiagnosticService, Error, OxcDiagnostic, GraphicalReportHandler, NamedSource};

fn my_tool() -> Result<()> {
    try_something().map_err(|e| OxcDiagnostic::error(e.to_string()))?;
    Ok(())
}

let (mut service, sender) = DiagnosticService::new(Box::new(GraphicalReportHandler::new()));

thread::spawn(move || {
    let file_path_being_processed = PathBuf::from("file.txt");
    let file_being_processed = Arc::new(NamedSource::new(file_path_being_processed.clone()));

    for _ in 0..10 {
        if let Err(diagnostic) = my_tool() {
            let report = diagnostic.with_source_code(Arc::clone(&file_being_processed));
            sender.send((file_path_being_processed, vec![Error::new(e)]));
        }
        // The service will stop when all senders are dropped
    }
});

service.run();

Modules§

reporter
Reporters for rendering and writing diagnostics.

Structs§

DiagnosticService
Listens for diagnostics sent over a channel by some job, and formats/reports them to the user.
GraphicalReportHandler
GraphicalTheme
Theme used by GraphicalReportHandler to render fancy Diagnostic reports.
LabeledSpan
A labeled SourceSpan.
NamedSource
Utility struct for when you have a regular SourceCode type that doesn’t implement name. For example String. Or if you want to override the name returned by the SourceCode.
OxcCode
OxcDiagnostic
Describes an error or warning that occurred.
OxcDiagnosticInner

Type Aliases§

DiagnosticSender
DiagnosticTuple
Error
Result
Severity