summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-10-15 09:39:32 +0300
committerLars Wirzenius <liw@liw.fi>2023-10-15 09:56:45 +0300
commit8ea3b2a70f9295b7e9b6c934b4a7fcc4074b3202 (patch)
treefaa00a1372d13b9a70bb98fc9942694d71da4417
parentb75f625d5cd3dd8d3a525e39aaf0d775ced2fb4d (diff)
downloadambient-run-8ea3b2a70f9295b7e9b6c934b4a7fcc4074b3202.tar.gz
fix: invalid YAML configuration files are reported as errors
Add scenarios to the subplot document to check for this, and fix the root cause of not exiting non-zero when there's an error. Signed-off-by: Lars Wirzenius <liw@liw.fi> Sponsored-by: author
-rw-r--r--ambient-run.md40
-rw-r--r--src/bin/ambient-run.rs1
-rw-r--r--src/config.rs2
3 files changed, 42 insertions, 1 deletions
diff --git a/ambient-run.md b/ambient-run.md
index db16dfb..7be3be6 100644
--- a/ambient-run.md
+++ b/ambient-run.md
@@ -461,6 +461,46 @@ then file extracted/README.md contains "my project!"
~~~
## Errors during build
+### Bad per-user configuration
+
+_Requirement:_ `ambient-run` fails if the per-user configuration is
+bad.
+
+_Justification:_ As a user I want to get an error if the configuration
+is wrong.
+
+_Stakeholder:_ Lars
+
+~~~scenario
+given an installed ambient-run
+given file garbage.yaml
+when I try to run ambient-run --config garbage.yaml config
+then command fails
+then stderr contains "garbage.yaml"
+~~~
+
+~~~{#garbage.yaml .file .yaml}
+This is not a valid YAML file.
+~~~
+
+### Bad per-project configuration
+
+_Requirement:_ `ambient-run` fails if the project configuration is
+bad.
+
+_Justification:_ As a user I want to get an error if the configuration
+is wrong.
+
+_Stakeholder:_ Lars
+
+~~~scenario
+given an installed ambient-run
+given file garbage.yaml
+when I try to run ambient-run project garbage.yaml
+then command fails
+then stderr contains "garbage.yaml"
+~~~
+
### Build produces too large an artifact
### Build produces too large a cache
### Build demands too many CPUs
diff --git a/src/bin/ambient-run.rs b/src/bin/ambient-run.rs
index 8157de7..6083286 100644
--- a/src/bin/ambient-run.rs
+++ b/src/bin/ambient-run.rs
@@ -19,6 +19,7 @@ fn main() {
eprintln!(" caused by: {}", underlying);
e = underlying.source();
}
+ std::process::exit(1);
}
}
diff --git a/src/config.rs b/src/config.rs
index 28e6e96..dfbe040 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -33,7 +33,7 @@ impl Config {
/// Load named configuration file, update self with values.
pub fn add_from(&mut self, filename: &Path) -> Result<(), ConfigError> {
- eprintln!("adding from {}", filename.display());
+ eprintln!("loading configuration from {}", filename.display());
let bytes = std::fs::read(filename).map_err(|e| ConfigError::Open(filename.into(), e))?;
let text = String::from_utf8_lossy(&bytes);
eprintln!("text: {:?}", text);