-
Notifications
You must be signed in to change notification settings - Fork 598
util: include stderr in cryptsetup errors #6036
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
base: devel
Are you sure you want to change the base?
util: include stderr in cryptsetup errors #6036
Conversation
iPraveenParihar
left a comment
There was a problem hiding this 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return stdout, stderr, fmt.Errorf("%s", baseErr) | |
| return stdout, stderr, errors.New(baseErr) |
1b4f034 to
221263a
Compare
internal/util/file/file.go
Outdated
| @@ -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() | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
nixpanic
left a comment
There was a problem hiding this 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>
221263a to
4e6b633
Compare
Done |
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
WriteStringfails insidefilepackage.