mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(resovler): impl Into for IOError (#1223)
patch for rspack issue [#4564](https://github.com/web-infra-dev/rspack/issues/4564)
This commit is contained in:
parent
b7e8feb7c1
commit
0fa24bcafc
2 changed files with 22 additions and 1 deletions
|
|
@ -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)))
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
@ -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…
Reference in a new issue