Fix lint errors#5897
Conversation
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
log.Fatalf calls os.Exit(1) and deferred functions are not called. This commit changes the _main function to return an integer and call os.Exit from main. Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
log.Fatal calls os.Exit, so the deferred functions are not called. This commit changes the _main function to return an integer and call os.Exit from main. This is a workaround to fix the lint errors. Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5897 +/- ##
==========================================
- Coverage 27.89% 27.88% -0.02%
==========================================
Files 519 519
Lines 55900 55923 +23
==========================================
Hits 15594 15594
- Misses 39108 39131 +23
Partials 1198 1198
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
|
||
| for _, ctg := range cfg.CommitCategories { | ||
| commits := make([]ReleaseCommit, 0, 0) | ||
| commits := make([]ReleaseCommit, 0) |
There was a problem hiding this comment.
| commits := make([]ReleaseCommit, 0) | |
| commits := make([]ReleaseCommit, 0, len(filteredCommits)) |
nits
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
| if err != nil { | ||
| log.Fatal(err) | ||
| log.Println(err) | ||
| return err |
There was a problem hiding this comment.
IMO, if this error is returned, and the caller prints again, it's redundant. If we don't have specific logic based on the error, then instead of returning the error, we should return the existing code. WDYT?
There was a problem hiding this comment.
I'm unsure about that.
Initially, I wrote as you said and thought it was not the standard go code to check whether the return value was zero.
Secondly, I wrote just return the error from the doComment, printed it on the caller side, and was a bit nervous about whether I had written all the logging.
Finally, I wrote logging in the doComment, returned an error, and didn't print it on the caller side.
There was a problem hiding this comment.
I see. Thanks for the clarification. Because I saw many places that perform "if error, then return 1, else return 0," I think it could be better to emit it as well. This means we logged the error and returned 0 and 1 from this doComment, and on the caller side, only returning doComment is enough.
There was a problem hiding this comment.
OK, I try to do it again.
There was a problem hiding this comment.
I changed doComment to return int. I think it's simpler than before. Thank you.
7f14722
| if err := doComment(failureBadgeURL + "\nUnable to run plan-preview. \ncause: " + err.Error()); err != nil { | ||
| return 1 | ||
| } | ||
| log.Println(err) | ||
| return 1 |
There was a problem hiding this comment.
This order?? err in doComment() is already printed in doComment(), and we want to print err of result, err := retrievePlanPreview( ??
(I'm not confident)
| if err := doComment(failureBadgeURL + "\nUnable to run plan-preview. \ncause: " + err.Error()); err != nil { | |
| return 1 | |
| } | |
| log.Println(err) | |
| return 1 | |
| log.Println(err) | |
| if err := doComment(failureBadgeURL + "\nUnable to run plan-preview. \ncause: " + err.Error()); err != nil { | |
| return 1 | |
| } | |
| return 1 |
There was a problem hiding this comment.
Yes, I want to print err from retrievePlanPreview.
The behavior differs when the doComment fails, my code doesn't print retrievePlanPreview's error, and your code does.
the doComment's error is shadowing the retrievePlanPreview's error and scope is narrow, so log.Println correctly prints err from retrievePlanPreview.
But I think it's better to print err from retrievePlanPreview even if doComment fails, so I'll apply your suggestion.
There was a problem hiding this comment.
I changed doComment to return int.
Additionally, this commit enables logging err from retrievePlanPreview without changing the order, and it's clear to read. I think it's enough. WDYT?
| if err := doComment(failureBadgeURL + "\nUnable to run plan-preview. \ncause: " + err.Error()); err != nil { | ||
| return 1 | ||
| } | ||
| log.Println(err) |
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev>
* Fix import grouping by make lint/go FIX=true Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Fix linter errors by make lint/go FIX=true Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Rewrite long if-else to switch Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Remove unnecessary zero-value initialization Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Remove unnecessary string conversion Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Fix to correctly call deferred functions log.Fatalf calls os.Exit(1) and deferred functions are not called. This commit changes the _main function to return an integer and call os.Exit from main. Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Fix lint errors log.Fatal calls os.Exit, so the deferred functions are not called. This commit changes the _main function to return an integer and call os.Exit from main. This is a workaround to fix the lint errors. Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Fix lint errors Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Initialize the slice with the correct capacity Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Change return type of doComment to int Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> --------- Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> Signed-off-by: pipecd-bot <pipecd.dev@gmail.com>
* Fix lint errors (#5897) * Fix import grouping by make lint/go FIX=true Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Fix linter errors by make lint/go FIX=true Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Rewrite long if-else to switch Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Remove unnecessary zero-value initialization Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Remove unnecessary string conversion Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Fix to correctly call deferred functions log.Fatalf calls os.Exit(1) and deferred functions are not called. This commit changes the _main function to return an integer and call os.Exit from main. Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Fix lint errors log.Fatal calls os.Exit, so the deferred functions are not called. This commit changes the _main function to return an integer and call os.Exit from main. This is a workaround to fix the lint errors. Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Fix lint errors Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Initialize the slice with the correct capacity Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> * Change return type of doComment to int Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> --------- Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> Signed-off-by: pipecd-bot <pipecd.dev@gmail.com> * Add 'title' to distinguish multiple projects in actions-plan-preview (#5905) * add title to args Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * Add the title to filter latest comments Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * Use hash Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * Fix tests Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * add multibyte test Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> --------- Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> Signed-off-by: pipecd-bot <pipecd.dev@gmail.com> * Revert "Do treeless clone for git clone to improve performance (#5722)" (#5908) This reverts commit 7e74937. Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> Signed-off-by: pipecd-bot <pipecd.dev@gmail.com> * Cut release v0.52.1 (#5909) Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Warashi <3600530+Warashi@users.noreply.github.com> Signed-off-by: pipecd-bot <pipecd.dev@gmail.com> --------- Signed-off-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> Signed-off-by: pipecd-bot <pipecd.dev@gmail.com> Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Shinnosuke Sawada-Dazai <shin@warashi.dev> Co-authored-by: Tetsuya KIKUCHI <97105818+t-kikuc@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Warashi <3600530+Warashi@users.noreply.github.com>
What this PR does:
func _main() intand calledos.Exit(_main())in the main.Why we need it:
Which issue(s) this PR fixes:
Does this PR introduce a user-facing change?: No