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

fix: --print-all-dependencies should handle unknown-deriver #70

Merged
merged 12 commits into from
Jul 10, 2024

Conversation

rsrohitsingh682
Copy link
Contributor

When nixci build fails while querying nix-store then we don't get proper error. It displays error like

nix-store --query --requisites --include-outputs failed to run (exited: 1).

We can add stderr messages to have proper error message.

Copy link
Owner

@srid srid left a comment

Choose a reason for hiding this comment

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

Could you also add similar stderr propagation for other functions in this module?

@@ -128,9 +128,11 @@ impl NixStoreCmd {
Ok(out)
} else {
let exit_code = out.status.code().unwrap_or(1);
let stderr_output = String::from_utf8(out.stderr)?;
Copy link
Owner

Choose a reason for hiding this comment

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

Should this not be from_utf8_lossy?

Copy link
Owner

@srid srid Jun 27, 2024

Choose a reason for hiding this comment

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

?;

Pretty much this causes the function to (unnecessarily) fail on decoding errors with stderr, which is something we don't care about. Lossy conversation is fine.

Copy link
Owner

@srid srid Jun 27, 2024

Choose a reason for hiding this comment

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

As an aside: must we capture stderr? Why not let the parent process inherit and stream it directly to the user (still in stderr)?

@srid srid changed the title nixci: print STDERR while querying nix-store requisites with outputs Display stderr on command failures during --print-all-dependencies Jun 27, 2024
@srid
Copy link
Owner

srid commented Jul 1, 2024

Could you also add similar stderr propagation for other functions in this module?

@rsrohitsingh682 ^

src/nix/nix_store.rs Outdated Show resolved Hide resolved
src/nix/nix_store.rs Outdated Show resolved Hide resolved
src/nix/nix_store.rs Outdated Show resolved Hide resolved
Comment on lines 108 to 110
let stderr = String::from_utf8(out.stderr).ok();
let exit_code = out.status.code();
Err(CommandError::ProcessFailed { stderr, exit_code }.into())
Copy link
Owner

Choose a reason for hiding this comment

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

There's a bug there. If UTF8 decoding fails, this sets stderr to None thus creating a false impression that no stderr is missing. Just use lossy decoding.

Comment on lines 143 to 145
let stderr = String::from_utf8(out.stderr).ok();
let exit_code = out.status.code();
Err(CommandError::ProcessFailed { stderr, exit_code }.into())
Copy link
Owner

Choose a reason for hiding this comment

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

Same


/// Errors when running and interpreting the output of a nix command
#[derive(Error, Debug)]
pub enum NixCmdError {
Copy link
Owner

Choose a reason for hiding this comment

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

You shouldn't use duplicate names for types in order to avoid confusion. NixCmdError already exists: https://github.com/juspay/nix-rs/blob/2dbba678a9e67925d964dbde24fbd8951ecbd2de/src/command.rs#L187

Suggested change
pub enum NixCmdError {
pub enum NixStoreCmdError {

Comment on lines 153 to 163
#[error("Command error: {0}")]
CmdError(#[from] CommandError),

#[error("Failed to decode command stdout (utf8 error): {0}")]
DecodeErrorUtf8(#[from] std::string::FromUtf8Error),

#[error("Failed to decode command stdout (from_str error): {0}")]
DecodeErrorFromStr(#[from] FromStrError),

#[error("Failed to decode command stdout (json error): {0}")]
DecodeErrorJson(#[from] serde_json::Error),
Copy link
Owner

@srid srid Jul 10, 2024

Choose a reason for hiding this comment

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

Why copy the fields rather than re-use NixCmdError directly here?

Copy link
Owner

Choose a reason for hiding this comment

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

#[error("Failed to decode command stdout (json error): {0}")]
DecodeErrorJson(#[from] serde_json::Error),

#[error("Unknown deriver in drv_path")]
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
#[error("Unknown deriver in drv_path")]
#[error("Unknown deriver")]

Comment on lines 169 to 178
#[derive(Debug)]
pub struct FromStrError(String);

impl Display for FromStrError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Failed to parse string: {}", self.0)
}
}

impl std::error::Error for FromStrError {}
Copy link
Owner

Choose a reason for hiding this comment

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

What's this for?

Comment on lines 180 to 198
#[derive(Error, Debug)]
pub enum CommandError {
#[error("Child process error: {0}")]
ChildProcessError(#[from] std::io::Error),
#[error(
"Process exited unsuccessfully. exit_code={:?}{}",
exit_code,
match stderr {
Some(s) => format!(" stderr={}", s),
None => "".to_string()
},
)]
ProcessFailed {
stderr: Option<String>,
exit_code: Option<i32>,
},
#[error("Failed to decode command stderr: {0}")]
Decode(#[from] std::string::FromUtf8Error),
}
Copy link
Owner

Choose a reason for hiding this comment

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

@srid srid changed the title Display stderr on command failures during --print-all-dependencies fix: --print-all-dependencies should handle unknown-deriver Jul 10, 2024
@srid srid merged commit 16815b6 into srid:master Jul 10, 2024
2 of 4 checks passed
@rsrohitsingh682 rsrohitsingh682 deleted the add-stderr branch July 10, 2024 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants