Skip to content

Commit

Permalink
Add custom error msg for missing crates (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
senekor authored Aug 12, 2024
1 parent fa2c1f1 commit b16278c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,17 @@ fn main() -> Result<()> {
r#"{"version": 2, "status": "error", "message": "One of the tests timed out"}"#,
);
} else if results_json.contains("probable build failure") {
results_json = format!(
r#"{{"version": 2, "status": "error", "message": "{}"}}"#,
results_out.escape_default()
);
if results_out.contains("error: no matching package named") {
results_json = format!(
r#"{{"version": 2, "status": "error", "message": "{}"}}"#,
escape(MISSING_CRATE_ERR_MSG)
);
} else {
results_json = format!(
r#"{{"version": 2, "status": "error", "message": "{}"}}"#,
escape(&results_out)
);
}
}

// only display relative path in output to students
Expand Down Expand Up @@ -118,3 +125,22 @@ fn determine_profile(input_dir: &Path) -> Result<&'static str> {
Ok("dev")
}
}

fn escape(s: &str) -> String {
// escape_default turns "'" into "\'" which is incorrect in json
// and needs to be reverted
s.escape_default().to_string().replace("\\'", "'")
}

static MISSING_CRATE_ERR_MSG: &str = "\
It looks like you're using a crate which isn't supported by our test runner.
Please see the file at the below URL to check which ones are supported.
Please get in touch if you think your crate should be included
or something else about the user experience could be improved.
List of available crates:
https://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml
Exercism forum (Rust topic):
https://forum.exercism.org/c/programming/rust
";
7 changes: 7 additions & 0 deletions tests/example-missing-crate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "example-missing-crate"
version = "0.1.0"
edition = "2021"

[dependencies]
lets-hope-nobody-publishes-a-crate-with-a-silly-name-like-this = "*"
5 changes: 5 additions & 0 deletions tests/example-missing-crate/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version": 2,
"status": "error",
"message": "It looks like you're using a crate which isn't supported by our test runner.\nPlease see the file at the below URL to check which ones are supported.\nPlease get in touch if you think your crate should be included\nor something else about the user experience could be improved.\n\nList of available crates:\nhttps://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml\n\nExercism forum (Rust topic):\nhttps://forum.exercism.org/c/programming/rust\n"
}
1 change: 1 addition & 0 deletions tests/example-missing-crate/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit b16278c

Please sign in to comment.