Skip to content

Commit

Permalink
chore: add some more context to file errors around sass (and others)
Browse files Browse the repository at this point in the history
Closes: trunk-rs#5
  • Loading branch information
ctron committed Nov 24, 2023
1 parent f0e8bbf commit 9b49521
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ pub async fn run_command(
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()
.with_context(|| format!("error spawning {} call", name))?
.with_context(|| format!("error spawning {name} call ({path})", path = path.display()))?
.wait()
.await
.with_context(|| format!("error during {} call", name))?;
.with_context(|| format!("error during {name} call"))?;
if !status.success() {
bail!("{} call returned a bad status", name);
bail!("{name} call returned a bad status");
}
Ok(())
}
13 changes: 9 additions & 4 deletions src/pipelines/sass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ impl Sass {
tracing::info!(path = ?rel_path, "compiling sass/scss");
common::run_command(Application::Sass.name(), &sass, args).await?;

let css = fs::read_to_string(&file_path).await?;
let css = fs::read_to_string(&file_path)
.await
.with_context(|| format!("error reading CSS result file '{file_path}'"))?;
fs::remove_file(&file_path).await?;

// Check if the specified SASS/SCSS file should be inlined.
Expand All @@ -103,9 +105,12 @@ impl Sass {
let file_path = self.cfg.staging_dist.join(&file_name);

// Write the generated CSS to the filesystem.
fs::write(&file_path, css)
.await
.context("error writing SASS pipeline output")?;
fs::write(&file_path, css).await.with_context(|| {
format!(
"error writing SASS pipeline output file '{}'",
file_path.display()
)
})?;

// Generate a hashed reference to the new CSS file.
CssRef::File(file_name)
Expand Down

0 comments on commit 9b49521

Please sign in to comment.