Skip to content

Commit

Permalink
Fixes for miette error handling change.
Browse files Browse the repository at this point in the history
Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
  • Loading branch information
dcookspi committed Dec 13, 2023
1 parent 9491522 commit 8923663
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
9 changes: 7 additions & 2 deletions crates/spfs-cli/common/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::panic::catch_unwind;
#[cfg(feature = "sentry")]
use std::sync::Mutex;

use miette::Error;
use miette::{Error, IntoDiagnostic, Result, WrapErr};
#[cfg(feature = "sentry")]
use once_cell::sync::OnceCell;
use spfs::io::Pluralize;
Expand Down Expand Up @@ -447,7 +447,12 @@ impl ExternalDataViewing {
"key".pluralize(num_keys),
keys.join(", ")
);
println!("{}", serde_yaml::to_string(&data)?);
println!(
"{}",
serde_yaml::to_string(&data)
.into_diagnostic()
.wrap_err("Failed to generate yaml output")?
);
} else if let Some(keys) = &self.get {
tracing::debug!("--get these keys: {}", keys.join(", "));
for key in keys.iter() {
Expand Down
22 changes: 13 additions & 9 deletions crates/spfs-cli/main/src/cmd_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::io;
use std::time::Instant;

use clap::{ArgGroup, Args};
use miette::{Context, Result};
use miette::{miette, Context, IntoDiagnostic, Result};
use spfs::runtime::KeyValuePair;
use spfs::storage::FromConfig;
use spfs::tracking::EnvSpec;
Expand Down Expand Up @@ -65,22 +65,26 @@ impl ExternalData {
// Treat '-' as "read from stdin"
Box::new(io::stdin())
} else {
Box::new(std::fs::File::open(filename).with_context(|| {
format!("Failed to open external data file: {filename:?}")
})?)
Box::new(
std::fs::File::open(filename)
.into_diagnostic()
.wrap_err(format!("Failed to open external data file: {filename:?}"))?,
)
};
let external_data: BTreeMap<String, String> = serde_yaml::from_reader(reader)
.with_context(|| {
format!("Failed to parse as external data key-value pairs: {filename:?}")
})?;
.into_diagnostic()
.wrap_err(format!(
"Failed to parse as external data key-value pairs: {filename:?}"
))?;
data.extend(external_data);
}

for pair in self.external_data.iter() {
let pair = pair.trim();
if pair.starts_with('{') {
let given: BTreeMap<String, String> = serde_yaml::from_str(pair)
.context("--external-data value looked like yaml, but could not be parsed")?;
.into_diagnostic()
.wrap_err("--external-data value looked like yaml, but could not be parsed")?;
data.extend(given);
continue;
}
Expand All @@ -89,7 +93,7 @@ impl ExternalData {
.split_once('=')
.or_else(|| pair.split_once(':'))
.ok_or_else(|| {
anyhow!(
miette!(
"Invalid option: -external-data {pair} (should be in the form name=value)"
)
})?;
Expand Down

0 comments on commit 8923663

Please sign in to comment.