Skip to content

Commit ce2c88a

Browse files
Improve target error message (#3555)
Signed-off-by: Brian Hardock <brian.hardock@fermyon.com>
1 parent 4b850b2 commit ce2c88a

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

crates/build/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,9 @@ mod tests {
589589

590590
assert!(err.contains("can't run in environment wasi-minimal"));
591591
assert!(err.contains("world wasi:cli/command@0.2.0"));
592-
assert!(err.contains("requires imports named"));
592+
assert!(
593+
err.contains("requires the following imports, which the environment does not provide")
594+
);
593595
assert!(err.contains("wasi:cli/stdout"));
594596
}
595597

crates/environments/src/environment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ mod test {
474474
"unexpected error {err}"
475475
);
476476
assert!(
477-
err.contains("requires imports named"),
477+
err.contains("requires the following imports, which the environment does not provide"),
478478
"unexpected error {err}"
479479
);
480480
assert!(
@@ -583,7 +583,7 @@ mod test {
583583
"unexpected error {err}"
584584
);
585585
assert!(
586-
err.contains("requires imports named"),
586+
err.contains("requires the following imports, which the environment does not provide"),
587587
"unexpected error {err}"
588588
);
589589
assert!(

crates/environments/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,14 @@ fn format_target_result_error(
288288
report: &wac_types::TargetValidationReport,
289289
) -> anyhow::Error {
290290
let mut error_string = format!(
291-
"Component {} ({}) can't run in environment {} because world {} ...\n",
292-
component_id, source_description, env_name, target_world_name
291+
"Component {component_id} ({source_description}) can't run in environment {env_name} (world {target_world_name}).\n",
293292
);
294293

295294
for (idx, import) in report.imports_not_in_target().enumerate() {
296295
if idx == 0 {
297-
error_string.push_str("... requires imports named\n - ");
296+
error_string.push_str(
297+
"The component requires the following imports, which the environment does not provide:\n - ",
298+
);
298299
} else {
299300
error_string.push_str(" - ");
300301
}
@@ -304,7 +305,9 @@ fn format_target_result_error(
304305

305306
for (idx, (export, export_kind)) in report.missing_exports().enumerate() {
306307
if idx == 0 {
307-
error_string.push_str("... requires exports named\n - ");
308+
error_string.push_str(
309+
"The environment requires the following exports, which the component does not provide:\n - ",
310+
);
308311
} else {
309312
error_string.push_str(" - ");
310313
}
@@ -315,7 +318,7 @@ fn format_target_result_error(
315318
}
316319

317320
for (name, extern_kind, error) in report.mismatched_types() {
318-
error_string.push_str("... found a type mismatch for ");
321+
error_string.push_str("Found a type mismatch for ");
319322
error_string.push_str(&format!("{extern_kind} {name}: {error}"));
320323
}
321324

0 commit comments

Comments
 (0)