Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(resovler): impl Into for IOError #1223

Merged
merged 2 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/oxc_resolver/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ impl PartialEq for IOError {
}
}

impl From<IOError> for std::io::Error {
fn from(error: IOError) -> Self {
let io_error = error.0.as_ref();
Self::new(io_error.kind(), io_error.to_string())
}
}

impl From<io::Error> for ResolveError {
fn from(err: io::Error) -> Self {
Self::IOError(IOError(Arc::new(err)))
Expand Down
16 changes: 15 additions & 1 deletion crates/oxc_resolver/src/tests/imports_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use serde_json::json;

use crate::{MatchObject, PathUtil, ResolveContext, ResolveError, ResolveOptions, Resolver};
use std::path::Path;
use std::{io::ErrorKind, path::Path};

#[test]
fn test() {
Expand Down Expand Up @@ -1296,3 +1296,17 @@ fn test_cases() {
}
}
}

#[test]
fn test_into_io_error() {
let error_string = "IOError occurred";
let string_error = std::io::Error::new(ErrorKind::Interrupted, error_string.to_string());
let resolve_io_error: ResolveError = string_error.into();

if let ResolveError::IOError(io_error) = resolve_io_error {
// fix for https://github.com/web-infra-dev/rspack/issues/4564
let std_io_error: std::io::Error = io_error.into();
assert_eq!(std_io_error.kind(), ErrorKind::Interrupted);
assert_eq!(std_io_error.to_string(), error_string);
}
}
Loading