Skip to content

Commit 906c790

Browse files
committed
chore: Implement std::error::Error::source for InlineError
1 parent 3fd5607 commit 906c790

5 files changed

Lines changed: 20 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Changed
66

77
- Display stylesheet location in network-related errors.
8+
- Implement `std::error::Error::source` for `InlineError`.
89

910
### Performance
1011

bindings/javascript/__test__/wasm.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,8 @@ test("unsupported network operation", (t) => {
8484
},
8585
{ any: true },
8686
);
87-
t.is(error, "Loading remote stylesheets is not supported on WASM");
87+
t.is(
88+
error,
89+
"Loading remote stylesheets is not supported on WASM: http://127.0.0.1:5000/external.css",
90+
);
8891
});

bindings/javascript/src/errors.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ impl From<InlineError> for JsValue {
4444
css_inline::InlineError::ParseError(e) => JsValue::from_str(e),
4545
css_inline::InlineError::Network {
4646
error: network_error,
47-
..
47+
location,
4848
} => {
4949
if let attohttpc::ErrorKind::Io(io_error) = network_error.kind() {
5050
if io_error.kind() == std::io::ErrorKind::Unsupported {
5151
return JsValue::from_str(
52-
"Loading remote stylesheets is not supported on WASM",
52+
format!(
53+
"Loading remote stylesheets is not supported on WASM: {location}"
54+
)
55+
.as_str(),
5356
);
5457
}
5558
}
128 Bytes
Binary file not shown.

css-inline/src/error.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,16 @@ impl From<io::Error> for InlineError {
3636
}
3737
}
3838

39-
impl Error for InlineError {}
39+
impl Error for InlineError {
40+
fn source(&self) -> Option<&(dyn Error + 'static)> {
41+
match self {
42+
InlineError::IO(error) => Some(error),
43+
#[cfg(feature = "http")]
44+
InlineError::Network { error, .. } => Some(error),
45+
InlineError::MissingStyleSheet { .. } | InlineError::ParseError(_) => None,
46+
}
47+
}
48+
}
4049

4150
impl Display for InlineError {
4251
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {

0 commit comments

Comments
 (0)