-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make
BuildError
newtype (#326)
<!-- Thank you for contributing! --> ### Description This is a preparation for supporting warnings and error tracing. We need add some fields on `BuildError`. <!-- Please insert your description here and provide especially info about the "what" this PR is solving --> ### Test Plan <!-- e.g. is there anything you'd like reviewers to focus on? --> ---
- Loading branch information
Showing
7 changed files
with
96 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::{ | ||
borrow::Cow, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
use miette::Diagnostic; | ||
use thiserror::Error; | ||
|
||
use crate::error_kind::{ | ||
external_entry::ExternalEntry, unresolved_entry::UnresolvedEntry, | ||
unresolved_import::UnresolvedImport, ErrorKind, | ||
}; | ||
|
||
type StaticStr = Cow<'static, str>; | ||
|
||
#[derive(Error, Debug, Diagnostic)] | ||
#[error(transparent)] | ||
#[diagnostic(transparent)] | ||
pub struct BuildError(ErrorKind); | ||
|
||
impl BuildError { | ||
pub fn new_with_kind(kind: ErrorKind) -> Self { | ||
Self(kind) | ||
} | ||
|
||
// --- Aligned with rollup | ||
pub fn entry_cannot_be_external(unresolved_id: impl AsRef<Path>) -> Self { | ||
Self::new_with_kind(ErrorKind::ExternalEntry( | ||
ExternalEntry { id: unresolved_id.as_ref().to_path_buf() }.into(), | ||
)) | ||
} | ||
|
||
pub fn unresolved_entry(unresolved_id: impl AsRef<Path>) -> Self { | ||
Self::new_with_kind(ErrorKind::UnresolvedEntry( | ||
UnresolvedEntry { unresolved_id: unresolved_id.as_ref().to_path_buf() }.into(), | ||
)) | ||
} | ||
|
||
pub fn unresolved_import(specifier: impl Into<StaticStr>, importer: impl Into<PathBuf>) -> Self { | ||
Self::new_with_kind(ErrorKind::UnresolvedImport( | ||
UnresolvedImport { specifier: specifier.into(), importer: importer.into() }.into(), | ||
)) | ||
} | ||
|
||
// --- rolldown specific | ||
pub fn napi_error(status: String, reason: String) -> Self { | ||
Self::new_with_kind(ErrorKind::Napi { status, reason }) | ||
} | ||
} | ||
|
||
impl From<std::io::Error> for BuildError { | ||
fn from(e: std::io::Error) -> Self { | ||
Self::new_with_kind(ErrorKind::Io(Box::new(e))) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::borrow::Cow; | ||
|
||
pub mod external_entry; | ||
// pub mod impl_to_diagnostic; | ||
pub mod unresolved_entry; | ||
pub mod unresolved_import; | ||
|
||
use miette::Diagnostic; | ||
use thiserror::Error; | ||
|
||
use self::{ | ||
external_entry::ExternalEntry, unresolved_entry::UnresolvedEntry, | ||
unresolved_import::UnresolvedImport, | ||
}; | ||
|
||
type StaticStr = Cow<'static, str>; | ||
|
||
#[derive(Error, Debug, Diagnostic)] | ||
pub enum ErrorKind { | ||
#[diagnostic(transparent)] | ||
#[error(transparent)] | ||
UnresolvedEntry(Box<UnresolvedEntry>), | ||
|
||
#[diagnostic(transparent)] | ||
#[error(transparent)] | ||
ExternalEntry(Box<ExternalEntry>), | ||
|
||
#[diagnostic(transparent)] | ||
#[error(transparent)] | ||
UnresolvedImport(Box<UnresolvedImport>), | ||
|
||
#[diagnostic(code = "IO_ERROR")] | ||
#[error(transparent)] | ||
Io(Box<std::io::Error>), | ||
|
||
// TODO: probably should remove this error | ||
#[diagnostic(code = "NAPI_ERROR")] | ||
#[error("Napi error: {status}: {reason}")] | ||
Napi { status: String, reason: String }, | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
mod error; | ||
// mod error_code; | ||
mod error_kind; | ||
mod utils; | ||
|
||
use std::path::Path; | ||
|