Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit error for missing exec.d paths #387

Merged
merged 2 commits into from
Mar 30, 2022

Conversation

Malax
Copy link
Member

@Malax Malax commented Mar 30, 2022

I recently messed up packaging my buildpack and all exec.d binaries were not properly packaged. The error messages made it hard to understand what was wrong since the error only complains about "file not found" but doesn't tell you anything about which file.

This PR adds an explicit error for missing exec.d paths so this error-case is much easier to debug. This is technically a breaking change for users that manually match libcnb::Error. Most users won't be affected if they rely on libcnb handling internal errors.

Closes GUS-W-10919490

@Malax Malax marked this pull request as ready for review March 30, 2022 10:38
@Malax Malax requested a review from edmorley March 30, 2022 10:38
Comment on lines +273 to +278
Some(&path)
.filter(|path| path.exists())
.ok_or_else(|| WriteLayerError::MissingExecDFile(path.clone()))
.and_then(|path| {
fs::copy(path, exec_d_dir.join(name)).map_err(WriteLayerError::IoError)
})?;
Copy link
Member

@edmorley edmorley Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementing using a conditional rather than a combinator seems a bit simpler, since:

  • it avoids the need to wrap in Some()
  • means the map_err is no longer required
  • means the .clone() is no longer required
  • IMO is just generally less nested and fewer words/parens to sift through when reading in this case
Suggested change
Some(&path)
.filter(|path| path.exists())
.ok_or_else(|| WriteLayerError::MissingExecDFile(path.clone()))
.and_then(|path| {
fs::copy(path, exec_d_dir.join(name)).map_err(WriteLayerError::IoError)
})?;
if !path.exists() {
return Err(WriteLayerError::MissingExecDFile(path));
}
fs::copy(path, exec_d_dir.join(name))?;

However I'm fine with it either way.

@edmorley
Copy link
Member

Thank you for fixing this - quick UX win! :-)

@Malax Malax merged commit 70fcf6a into main Mar 30, 2022
@Malax Malax deleted the malax/missing-execd-path-explicit-error branch March 30, 2022 13:57
@edmorley edmorley added the enhancement New feature or request label Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants