Skip to content

[Enhance]: Improving SWC's Error Recovery for more friendly experience #10192

@GiveMe-A-Name

Description

@GiveMe-A-Name

Describe the feature

The try_with_handler should return a SwcError instead of anyhow!(msg), it's helper upper application such as deno, rspack can get more detail about error.
Swc have many kind error with invoke wasm plugin error, wasm plugin emit custom error, js parser error ...., So upper application need more detail to distinguish what the error kind.

Example

// crate  swc_error_reporter
pub struct Error {
    inner: Box<InnerError>
}

struct InnerError {
   kind: ErrorKind,
   message: Cow<str>,
   ....
}

impl Display for Error { .. }

fn try_with_handler(...) -> Result<T, Error> { ... }
// rspack/core

match swc_try_with_handler {
      Ok(program) => program,
      Err(error) => {
          match error.kind() {
             // do somethings for different errors
          }
      },
}
// node_binding

#[napi] 
fn transform_sync(...) -> Result<T> {
   swc_core::transform(...).map_err(|e: SwcError| anyhow!(e.to_string()))
}

Babel plugin or link to the feature description

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions