Skip to content

Conversation

@black-dragon74
Copy link
Member

Describe what this PR does

This patch includes the stderr when an error is encountered in cryptsetup.

This patch additionally fixes a potential memory leak which could occur if WriteString fails inside file package.

Copy link
Contributor

@iPraveenParihar iPraveenParihar left a comment

Choose a reason for hiding this comment

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

nit

return &result
}
// Include stderr if not empty
baseErr := fmt.Sprintf("an error (%v) occurred while running %s args: %v", err, program, sanitizedArgs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
baseErr := fmt.Sprintf("an error (%v) occurred while running %s args: %v", err, program, sanitizedArgs)
baseErr := fmt.Errof("error running %s args: %v: %w", program, sanitizedArgs: err)

size, err := strconv.ParseUint(input, 10, 32)
if err != nil {
return fmt.Errorf("could not parse number from %q: %w", input, err)
return stdout, stderr, fmt.Errorf("%s", baseErr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return stdout, stderr, fmt.Errorf("%s", baseErr)
return stdout, stderr, errors.New(baseErr)

@@ -34,6 +34,8 @@ func CreateTempFile(prefix, contents string) (*os.File, error) {
// In case of error, remove the file if it was created
defer func() {
if err != nil {
//nolint:errcheck // may return file already closed in happy path
_ = file.Close()
Copy link
Member

Choose a reason for hiding this comment

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

Instead of closing the file below, sync/flush the contents and always close it in the deferred statement here. The sync/flush error is more important than the close error, which just can be logged.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@nixpanic nixpanic left a comment

Choose a reason for hiding this comment

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

Both changes look unrelated, it is probably cleaner to split them into their own commits.

This patch includes the stderr when an error is encountered
in cryptsetup.

Signed-off-by: Niraj Yadav <niryadav@redhat.com>
This patch makes changes which ensure that the content for
tempfile is flushed to disk before returning the handle.

It also silently ignores errors when closing and removing the
file as sync error has more weightage than these.

Signed-off-by: Niraj Yadav <niryadav@redhat.com>
@black-dragon74 black-dragon74 force-pushed the cryptsetup-err-inc-stderr branch from 221263a to 4e6b633 Compare February 12, 2026 09:53
@black-dragon74
Copy link
Member Author

Both changes look unrelated, it is probably cleaner to split them into their own commits.

Done

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.

3 participants