Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion features/custom_vars/file.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Feature: define a custom variable with a part of the filename
Then it prints
"""
Error: cannot determine command for trigger: test-file my_file.go
Please make sure that this action is listed in your configuration file
Please make sure that this action is listed in contest.json
"""
# ensure the server is still running and functional
When receiving the command '{ "command": "test-file", "file": "my_file.ts" }'
Expand Down
2 changes: 1 addition & 1 deletion features/test_types/test_file.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Feature: run all tests in a file
Then it prints
"""
Error: cannot determine command for trigger: test-file foo.go
Please make sure that this action is listed in your configuration file
Please make sure that this action is listed in contest.json
"""
# ensure the server is still running and functional
When receiving the command '{ "command": "test-file", "file": "test/chars.test.ts" }'
Expand Down
2 changes: 1 addition & 1 deletion features/test_types/test_file_line.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Feature: test only a specific function
Then it prints
"""
Error: cannot determine command for trigger: test-file-line foo.go:23
Please make sure that this action is listed in your configuration file
Please make sure that this action is listed in contest.json
"""
# ensure the server is still running and functional
When receiving the command '{ "command": "test-file-line", "file": "foo.ts", "line": 23 }'
Expand Down
2 changes: 1 addition & 1 deletion src/cli/print_error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{UserError, subshell};

pub fn print_error(err: &UserError) {
pub fn print_error(err: UserError) {
let (msg, guidance) = err.messages();
println!("Error: {msg}");
if let Some(guidance) = guidance {
Expand Down
2 changes: 1 addition & 1 deletion src/config/data/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::fmt::{self, Display};
use std::{fs, io};

/// filename of the Contest config file
const JSON_PATH: &str = "contest.json";
pub const JSON_PATH: &str = "contest.json";

#[derive(Debug, Default, PartialEq)]
pub struct Configuration {
Expand Down
2 changes: 1 addition & 1 deletion src/config/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod var_source;
pub use action::Action;
pub use after_run::AfterRun;
pub use before_run::BeforeRun;
pub use configuration::Configuration;
pub use configuration::{Configuration, JSON_PATH};
pub use options::Options;
pub use pattern::Pattern;
pub use var::Var;
Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
mod data;
pub mod file;

pub use data::{Action, AfterRun, BeforeRun, Configuration, Options, Pattern, Var, VarSource};
pub use data::{Action, AfterRun, BeforeRun, Configuration, JSON_PATH, Options, Pattern, Var, VarSource};
41 changes: 24 additions & 17 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! error types used in this app

use crate::config;
use crate::config::file::ActionType;
use big_s::S;

Expand Down Expand Up @@ -42,7 +43,7 @@ pub enum UserError {
impl UserError {
/// Provides human-readable messages for `UserError`.
#[must_use]
pub fn messages(&self) -> (String, Option<&str>) {
pub fn messages(self) -> (String, Option<String>) {
match self {
UserError::CannotCreateConfigFile { err } => (format!("cannot create configuration file: {err}"), None),
UserError::CannotDetermineCurrentDirectory { err } => (format!("cannot determine the current directory: {err}"), None),
Expand All @@ -53,51 +54,57 @@ impl UserError {
UserError::ConfigInvalidGlob { pattern, err } => (format!("Invalid glob pattern: {pattern}"), Some(err)),
UserError::FifoAlreadyExists { path } => (
format!("A fifo pipe \"{path}\" already exists."),
Some("This could mean a Contest instance could already be running.\nIf you are sure no other instance is running, please delete this file and start Contest again."),
Some(S(
"This could mean a Contest instance could already be running.\nIf you are sure no other instance is running, please start Contest again.",
)),
),
UserError::FifoCannotCreate { err, path } => (format!("Cannot create pipe at {path}: {err}"), None),
UserError::FifoCannotDelete { err, path } => (format!("Cannot delete pipe at {path}: {err}"), None),
UserError::FifoCannotRead { err } => (format!("Cannot read from pipe: {err}"), Some("This is an internal error")),
UserError::FifoCannotOpen { err } => (format!("Cannot open pipe: {err}"), Some("This is an internal error")),
UserError::FifoCannotRead { err } => (format!("Cannot read from pipe: {err}"), Some(S("This is an internal error"))),
UserError::FifoCannotOpen { err } => (format!("Cannot open pipe: {err}"), Some(S("This is an internal error"))),
UserError::FileNameNotAvailable => (
S("Filename is not known"),
Some(r#"To use the filename in a variable, you need to choose either the "test-file" or "test-file-line" action type that provides this data."#),
Some(S(
r#"To use the filename in a variable, you need to choose either the "test-file" or "test-file-line" action type that provides this data."#,
)),
),
UserError::FilesIsEmpty => (S(r#"The "files" field in your config file is empty"#), None),
UserError::InvalidRegex { regex, err } => (format!("invalid regex: {regex}"), Some(err)),
UserError::InvalidTrigger { source: line, err } => (format!("cannot parse command received from client: {line}"), Some(err)),
UserError::LineIsNotANumber { line } => (format!("the provided line ({line})is not a number"), None),
UserError::LineNotAvailable => (
S("Line not available"),
Some(r#"To use the current line in a variable, you need to use the "test-file-line" action type that provides this data."#),
Some(S(
r#"To use the current line in a variable, you need to use the "test-file-line" action type that provides this data."#,
)),
),
UserError::MissingFilesInPattern => (S(r#"the pattern in the config file is missing the "files" field."#), None),
UserError::MissingFileInTrigger { original } => (format!("invalid trigger received: {original}"), Some(r#"missing "file" field"#)),
UserError::MissingFileAndLineInTrigger { original } => (format!("invalid trigger received: {original}"), Some(r#"missing "file" and "line" fields"#)),
UserError::MissingFilesInTestFile { original } => (format!("invalid trigger received: {original}"), Some(r#"missing "files" field"#)),
UserError::MissingLineInTrigger { original } => (format!("invalid trigger received: {original}"), Some(r#"missing "line" field"#)),
UserError::MissingRunInTrigger { original } => (format!("invalid trigger received: {original}"), Some(r#"missing "run" field"#)),
UserError::NoCommandToRepeat => (S("No command to repeat found"), Some("You must submit a test command first before you can repeat it.")),
UserError::MissingFileInTrigger { original } => (format!("invalid trigger received: {original}"), Some(S(r#"missing "file" field"#))),
UserError::MissingFileAndLineInTrigger { original } => (format!("invalid trigger received: {original}"), Some(S(r#"missing "file" and "line" fields"#))),
UserError::MissingFilesInTestFile { original } => (format!("invalid trigger received: {original}"), Some(S(r#"missing "files" field"#))),
UserError::MissingLineInTrigger { original } => (format!("invalid trigger received: {original}"), Some(S(r#"missing "line" field"#))),
UserError::MissingRunInTrigger { original } => (format!("invalid trigger received: {original}"), Some(S(r#"missing "run" field"#))),
UserError::NoCommandToRepeat => (S("No command to repeat found"), Some(S("You must submit a test command first before you can repeat it."))),
UserError::RunCommandNotFound { command } => (
format!("test command to run not found: {command}"),
Some("Please verify that the command is in the path or fix your config file."),
Some(S("Please verify that the command is in the path or fix your config file.")),
),
UserError::RunCommandIsEmpty => (S(r#"the "run" field in your configuration file is empty"#), None),
UserError::TriggerTooManyCaptures { count, regex, line } => (
format!("found {count} captures using regex \"{regex}\" on line: {line}"),
Some("filters in the Contest configuration file can only contain one capture group"),
Some(S("filters in the Contest configuration file can only contain one capture group")),
),
UserError::TriggerRegexNotFound { regex, filename, line } => (
format!("did not find pattern {regex} in file {filename} at line {line}"),
Some("This is defined in file contest.json."),
Some(S("This is defined in file contest.json.")),
),
UserError::UnknownActionType { action_type } => (
format!("unknown action type: {action_type}"),
Some(r#"Valid types are "test-all", "test-file", and "test-file-line"."#),
Some(S(r#"Valid types are "test-all", "test-file", and "test-file-line"."#)),
),
UserError::UnknownTrigger { source } => (
format!("cannot determine command for trigger: {source}"),
Some("Please make sure that this action is listed in your configuration file"),
Some(format!("Please make sure that this action is listed in {}", config::JSON_PATH)),
),
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ fn run_command(trigger: &Trigger, configuration: &config::Configuration, last_co
Err(err) => match err {
UserError::NoCommandToRepeat => {
// repeat non-existing command --> don't stop, just print an error message and keep going
cli::print_error(&err);
cli::print_error(err);
return Ok(subshell::Outcome::TestFail);
}
UserError::TriggerRegexNotFound { regex: _, filename: _, line: _ } => {
// user triggered a command in a place where it doesn't match all regexes --> let them know and go to the correct location
cli::print_error(&err);
cli::print_error(err);
return Ok(subshell::Outcome::TestFail);
}
UserError::UnknownTrigger { source: _ } => {
// user sent a trigger from the wrong file --> let them know and send one from the correct file
cli::print_error(&err);
cli::print_error(err);
return Ok(subshell::Outcome::TestFail);
}
_ => return Err(err),
Expand Down