Skip to content

Commit c7e0ed4

Browse files
authored
refactor: replace expect("TODO") with descriptive error messages (#13685)
1 parent 2f2a558 commit c7e0ed4

File tree

9 files changed

+30
-14
lines changed

9 files changed

+30
-14
lines changed

crates/rspack_binding_api/src/codegen_result.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ impl From<&CodeGenerationResults> for JsCodegenerationResults {
4747
runtime_map.insert(
4848
get_runtime_key(runtime_result_map.single_runtime.as_ref().expect("exist")).clone(),
4949
id_result_map
50-
.get(&runtime_result_map.single_value.expect("TODO"))
51-
.expect("TODO")
50+
.get(
51+
&runtime_result_map
52+
.single_value
53+
.expect("should have single value in SingleEntry mode"),
54+
)
55+
.expect("should have codegen result for single value")
5256
.as_ref()
5357
.into(),
5458
);
@@ -57,7 +61,11 @@ impl From<&CodeGenerationResults> for JsCodegenerationResults {
5761
runtime_result_map.map.iter().for_each(|(k, v)| {
5862
runtime_map.insert(
5963
k.clone(),
60-
id_result_map.get(v).expect("TODO").as_ref().into(),
64+
id_result_map
65+
.get(v)
66+
.expect("should have codegen result for runtime value")
67+
.as_ref()
68+
.into(),
6169
);
6270
});
6371
}

crates/rspack_core/src/options/output.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl PublicPath {
417417

418418
impl Default for PublicPath {
419419
fn default() -> Self {
420-
Self::from_str("/").expect("TODO:")
420+
Self::from_str("/").expect("'/' should be a valid public path")
421421
}
422422
}
423423

crates/rspack_core/src/plugin/plugin_driver.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ impl PluginDriver {
5252
compiler_options: &options,
5353
};
5454
for plugin in &plugins {
55-
plugin.apply(&mut apply_context).expect("TODO:");
55+
plugin
56+
.apply(&mut apply_context)
57+
.expect("should apply plugin successfully");
5658
}
5759

5860
Arc::new(Self {
@@ -71,7 +73,10 @@ impl PluginDriver {
7173
}
7274

7375
pub fn take_diagnostic(&self) -> Vec<Diagnostic> {
74-
let mut diagnostic = self.diagnostics.lock().expect("TODO:");
76+
let mut diagnostic = self
77+
.diagnostics
78+
.lock()
79+
.expect("should be able to lock diagnostics");
7580
std::mem::take(&mut diagnostic)
7681
}
7782

crates/rspack_javascript_compiler/src/compiler/minify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl JavaScriptCompiler {
7878
_ => SourceMapsConfig::Bool(false),
7979
})
8080
})
81-
.expect("TODO:");
81+
.expect("should have source map config");
8282

8383
let mut min_opts = MinifyOptions {
8484
compress: opts

crates/rspack_plugin_css/src/plugin/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ impl CssPlugin {
126126
// done, everything empty
127127
break;
128128
}
129-
let mut selected_module = *list.last().expect("TODO:");
129+
let mut selected_module = *list.last().expect("list should not be empty");
130130
let mut has_failed = None;
131131
'outer: loop {
132132
for SortedModules { set, list } in &modules_by_chunk_group {
133133
if list.is_empty() {
134134
continue;
135135
}
136-
let last_module = *list.last().expect("TODO:");
136+
let last_module = *list.last().expect("list should not be empty");
137137
if last_module.identifier() == selected_module.identifier() {
138138
continue;
139139
}

crates/rspack_plugin_html/src/asset.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ impl HtmlPluginAssets {
8585
.map(|entry_name| compilation.entrypoint_by_name(entry_name))
8686
.flat_map(|entry| entry.get_files(&compilation.build_chunk_graph_artifact.chunk_by_ukey))
8787
.filter_map(|asset_name| {
88-
let asset = compilation.assets().get(&asset_name).expect("TODO:");
88+
let asset = compilation
89+
.assets()
90+
.get(&asset_name)
91+
.expect("should have asset for entrypoint file");
8992
if asset.info.hot_module_replacement.unwrap_or(false)
9093
|| asset.info.development.unwrap_or(false)
9194
{

crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_export_require_dependency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ impl DependencyTemplate for CommonJsExportRequireDependencyTemplate {
553553
};
554554
source.replace(dep.range.start, dep.range.end, expr, None)
555555
} else if dep.base.is_define_property() {
556-
panic!("TODO")
556+
todo!("CommonJsExportRequireDependency define_property base type")
557557
} else {
558558
panic!("Unexpected type");
559559
}

crates/rspack_plugin_progress/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl ProgressPlugin {
101101
let progress_bar = MULTI_PROGRESS.add(ProgressBar::new(100));
102102

103103
let mut progress_bar_style = ProgressStyle::with_template(&options.template)
104-
.expect("TODO:")
104+
.expect("should be a valid progress bar template")
105105
.progress_chars(&options.progress_chars);
106106
if let Some(tick_strings) = &options.tick_strings {
107107
progress_bar_style = progress_bar_style.tick_strings(

crates/rspack_util/src/identifier.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use regex::Regex;
1010
use sugar_path::SugarPath;
1111

1212
static SEGMENTS_SPLIT_REGEXP: LazyLock<Regex> =
13-
LazyLock::new(|| Regex::new(r"([|!])").expect("TODO:"));
13+
LazyLock::new(|| Regex::new(r"([|!])").expect("should be a valid regex"));
1414
static WINDOWS_ABS_PATH_REGEXP: LazyLock<Regex> =
15-
LazyLock::new(|| Regex::new(r"^[a-zA-Z]:[/\\]").expect("TODO:"));
15+
LazyLock::new(|| Regex::new(r"^[a-zA-Z]:[/\\]").expect("should be a valid regex"));
1616
static WINDOWS_PATH_SEPARATOR: &[char] = &['/', '\\'];
1717

1818
/// # Example

0 commit comments

Comments
 (0)