summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2021-10-08 22:30:03 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2021-10-08 22:31:11 +0100
commit409f32c5017d3f880e003138b0548cf74f965ce0 (patch)
treece2a0237239d5f6a145e0bb59193d487f8d0fbea
parentada9be82cc7cc0995e14235d88f70d641aa81483 (diff)
downloadsubplot-409f32c5017d3f880e003138b0548cf74f965ce0.tar.gz
codegen: Refuse to codegen if there are zero scenarios
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rw-r--r--src/codegen.rs8
-rw-r--r--src/error.rs4
2 files changed, 11 insertions, 1 deletions
diff --git a/src/codegen.rs b/src/codegen.rs
index 89ea591..b67d94a 100644
--- a/src/codegen.rs
+++ b/src/codegen.rs
@@ -39,7 +39,8 @@ pub fn generate_test_program(
fn context(doc: &mut Document, template: &str) -> Result<Context, SubplotError> {
let mut context = Context::new();
- context.insert("scenarios", &doc.matched_scenarios(template)?);
+ let scenarios = doc.matched_scenarios(template)?;
+ context.insert("scenarios", &scenarios);
context.insert("files", doc.files());
let funcs_filenames = doc.meta().functions_filenames();
@@ -51,6 +52,11 @@ fn context(doc: &mut Document, template: &str) -> Result<Context, SubplotError>
}
context.insert("functions", &funcs);
+ // Any of the above could fail for more serious reasons, but if we get this far
+ // and our context would have no scenarios in it, then we complain.
+ if scenarios.is_empty() {
+ return Err(SubplotError::NoScenariosMatched(template.to_string()));
+ }
Ok(context)
}
diff --git a/src/error.rs b/src/error.rs
index e69bffe..c041eaf 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -233,6 +233,10 @@ pub enum SubplotError {
#[error("failure rendering pikchr diagram: {0}")]
PikchrRenderError(String),
+ /// When attempting to codegen, no scenarios matched the desired template language
+ #[error("no scenarios were found matching the `{0}` template")]
+ NoScenariosMatched(String),
+
/// I/O error
///
/// Subplot did some I/O, and it failed. This is a generic wrapper