Skip to content

Commit

Permalink
fix(core): don't panic when load config failed (#7693)
Browse files Browse the repository at this point in the history
  • Loading branch information
hardfist authored Aug 27, 2024
1 parent 6d31029 commit 0665cbc
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions crates/rspack_binding_options/src/plugins/js_loader/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ impl Identifiable for JsLoader {
}
}

pub fn get_builtin_loader(builtin: &str, options: Option<&str>) -> BoxLoader {
pub fn get_builtin_loader(builtin: &str, options: Option<&str>) -> Result<BoxLoader> {
if builtin.starts_with(SWC_LOADER_IDENTIFIER) {
return Arc::new(
rspack_loader_swc::SwcLoader::new(
serde_json::from_str(options.unwrap_or("{}")).unwrap_or_else(|e| {
panic!("Could not parse builtin:swc-loader options:{options:?},error: {e:?}")
}),
)
return Ok(Arc::new(
rspack_loader_swc::SwcLoader::new(serde_json::from_str(options.unwrap_or("{}")).map_err(
|e| error!("Could not parse builtin:swc-loader options:{options:?},error: {e:?}"),
)?)
.with_identifier(builtin.into()),
);
));
}

if builtin.starts_with(LIGHTNINGCSS_LOADER_IDENTIFIER) {
Expand All @@ -44,33 +42,35 @@ pub fn get_builtin_loader(builtin: &str, options: Option<&str>) -> BoxLoader {
panic!("Could not parse builtin:lightningcss-loader options:{options:?},error: {e:?}")
});
// TODO: builtin-loader supports function
return Arc::new(rspack_loader_lightningcss::LightningCssLoader::new(
None,
config.try_into().unwrap_or_else(|e| {
panic!("Could not parse builtin:lightningcss-loader options:{options:?},error: {e:?}")
}),
builtin,
return Ok(Arc::new(
rspack_loader_lightningcss::LightningCssLoader::new(
None,
config.try_into().unwrap_or_else(|e| {
panic!("Could not parse builtin:lightningcss-loader options:{options:?},error: {e:?}")
}),
builtin,
),
));
}

if builtin.starts_with(REACT_REFRESH_LOADER_IDENTIFIER) {
return Arc::new(
return Ok(Arc::new(
rspack_loader_react_refresh::ReactRefreshLoader::default().with_identifier(builtin.into()),
);
));
}
if builtin.starts_with(PREACT_REFRESH_LOADER_IDENTIFIER) {
return Arc::new(
return Ok(Arc::new(
rspack_loader_preact_refresh::PreactRefreshLoader::default().with_identifier(builtin.into()),
);
));
}
if builtin.starts_with(rspack_loader_testing::SIMPLE_ASYNC_LOADER_IDENTIFIER) {
return Arc::new(rspack_loader_testing::SimpleAsyncLoader);
return Ok(Arc::new(rspack_loader_testing::SimpleAsyncLoader));
}
if builtin.starts_with(rspack_loader_testing::SIMPLE_LOADER_IDENTIFIER) {
return Arc::new(rspack_loader_testing::SimpleLoader);
return Ok(Arc::new(rspack_loader_testing::SimpleLoader));
}
if builtin.starts_with(rspack_loader_testing::PITCHING_LOADER_IDENTIFIER) {
return Arc::new(rspack_loader_testing::PitchingLoader);
return Ok(Arc::new(rspack_loader_testing::PitchingLoader));
}
unreachable!("Unexpected builtin loader: {builtin}")
}
Expand All @@ -95,7 +95,7 @@ pub(crate) async fn resolve_loader(

// FIXME: not belong to napi
if loader_request.starts_with(BUILTIN_LOADER_PREFIX) {
return Ok(Some(get_builtin_loader(loader_request, loader_options)));
return get_builtin_loader(loader_request, loader_options).map(Some);
}

let resolve_result = resolver
Expand Down

2 comments on commit 0665cbc

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Benchmark detail: Open

Name Base (2024-08-27 a33dd61) Current Change
10000_development-mode + exec 2.27 s ± 31 ms 2.28 s ± 27 ms +0.44 %
10000_development-mode_hmr + exec 701 ms ± 13 ms 706 ms ± 20 ms +0.73 %
10000_production-mode + exec 2.94 s ± 44 ms 2.97 s ± 54 ms +0.85 %
arco-pro_development-mode + exec 1.9 s ± 81 ms 1.89 s ± 72 ms -0.57 %
arco-pro_development-mode_hmr + exec 435 ms ± 2.4 ms 437 ms ± 4.7 ms +0.30 %
arco-pro_production-mode + exec 3.4 s ± 84 ms 3.44 s ± 59 ms +1.06 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.49 s ± 69 ms 3.48 s ± 63 ms -0.52 %
threejs_development-mode_10x + exec 1.7 s ± 13 ms 1.71 s ± 22 ms +0.57 %
threejs_development-mode_10x_hmr + exec 829 ms ± 9.9 ms 830 ms ± 15 ms +0.12 %
threejs_production-mode_10x + exec 5.48 s ± 30 ms 5.5 s ± 75 ms +0.37 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
nx ❌ failure
rspress ✅ success
rslib ❌ failure
rsbuild ✅ success
examples ✅ success

Please sign in to comment.