Skip to content
Merged
Changes from 1 commit
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
24 changes: 20 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::collections::HashSet;
use std::path::Path;

use pyo3::exceptions::PyValueError;
use pyo3::exceptions::{PyValueError, PyIOError};
use pyo3::prelude::*;

use browserslist::Error as BrowserslistError;
use lightningcss::bundler::{Bundler, FileProvider};
use lightningcss::bundler::{Bundler, FileProvider, BundleErrorKind};
use lightningcss::stylesheet::{
MinifyOptions, ParserFlags, ParserOptions, PrinterOptions, StyleSheet,
};
Expand Down Expand Up @@ -49,7 +49,7 @@ fn process_stylesheet(code: &str,

let targets = match mk_targets(browsers_list) {
Ok(val) => val,
Err(e) => {return Err(PyValueError::new_err(format!("browsers_list failed validation: {}", e.to_string())))}
Err(e) => {return Err(PyValueError::new_err(format!("Browsers_list failed validation: {}", e.to_string())))}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave the capitalization matching the parameter name. We could phrase it differently though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. My OCD got the better of me.

};
let mut stylesheet = match StyleSheet::parse(code, mk_parser_options(filename, error_recovery, parser_flags)) {
Ok(val) => val,
Expand Down Expand Up @@ -142,7 +142,23 @@ fn bundle_css(
..Default::default()
},
);
let mut stylesheet = bundler.bundle(Path::new(path)).unwrap();

let mut stylesheet = match bundler.bundle(Path::new(path)) {
Ok(s) => s,
Err(e) => {
let message = e.to_string();
match e.kind {
// Resolver errors, probably related to file I/O
BundleErrorKind::ResolverError(_) => {
return Err(PyIOError::new_err(format!("Bundling failed: {}", message)));
}
// Parser and logical errors
_ => {
return Err(PyValueError::new_err(format!("Bundling failed: {}", message)));
}
}
}
};

let targets = match mk_targets(browsers_list) {
Ok(val) => val,
Expand Down