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(report): close the file #4842

Merged
merged 6 commits into from
Jul 23, 2023
Merged

Conversation

knqyf263
Copy link
Collaborator

@knqyf263 knqyf263 commented Jul 19, 2023

Description

Close the output file. Also, this PR treats the output value as string so that we can add support for #4451.

Also, this PR defines type Format string.

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

Copy link
Contributor

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

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

LGTM.
Left 1 idea.

Comment on lines 82 to 90
output := os.Stdout
if option.Output != "" {
f, err := os.Create(option.Output)
if err != nil {
return xerrors.Errorf("failed to create a file: %w", err)
}
output = f
defer f.Close()
}
Copy link
Contributor

@DmitriyLewen DmitriyLewen Jul 20, 2023

Choose a reason for hiding this comment

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

@@ -1218,13 +1207,12 @@ func showVersion(cacheDir, outputFormat, version string, outputWriter io.Writer)

switch outputFormat {
case "json":
b, _ := json.Marshal(VersionInfo{
_ = json.NewEncoder(w).Encode(VersionInfo{
Copy link
Contributor

Choose a reason for hiding this comment

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

error is ignored here, was it done intentionally ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is not the code I added, and I have no idea why the error was ignored initially. But it looks like we should handle it. Fixed in 1417f18.

@knqyf263 knqyf263 added this pull request to the merge queue Jul 23, 2023
Merged via the queue into aquasecurity:main with commit 20c2246 Jul 23, 2023
12 checks passed
@knqyf263 knqyf263 deleted the close_output branch July 23, 2023 14:01
AnaisUrlichs pushed a commit to AnaisUrlichs/trivy that referenced this pull request Aug 10, 2023
* fix(report): close the file

* refactor: add the format type

* fix: return errors in version printing

* fix: lint issues

* fix: do not fail on bogus cache dir

---------

Co-authored-by: DmitriyLewen <dmitriy.lewen@smartforce.io>
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.

Close output file after writing the report
3 participants