-
Notifications
You must be signed in to change notification settings - Fork 48
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
downgrade yamlfmt to go 1.18 #105
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
- id: yamlfmt | ||
name: yamlfmt | ||
description: This hook uses github.com/google/yamlfmt to format yaml files. Requires golang >1.20 to be installed. | ||
description: This hook uses github.com/google/yamlfmt to format yaml files. Requires golang >1.18 to be installed. | ||
entry: yamlfmt | ||
language: golang | ||
types: [yaml] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package collections | ||
|
||
import "errors" | ||
|
||
type Errors []error | ||
|
||
func (errs Errors) Combine() error { | ||
errMessage := "" | ||
|
||
for _, err := range errs { | ||
if err != nil { | ||
errMessage += err.Error() + "\n" | ||
} | ||
} | ||
|
||
if len(errMessage) == 0 { | ||
return nil | ||
} | ||
return errors.New(errMessage) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package collections_test | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/yamlfmt/internal/collections" | ||
) | ||
|
||
func TestErrorsCombine(t *testing.T) { | ||
errs := collections.Errors{ | ||
errors.New("a"), | ||
nil, | ||
errors.New("c"), | ||
} | ||
err := errs.Combine() | ||
if err == nil { | ||
t.Fatal("expected combined err not to be nil") | ||
} | ||
for _, errEl := range errs { | ||
if errEl == nil { | ||
continue | ||
} | ||
if !strings.Contains(err.Error(), errEl.Error()) { | ||
t.Fatalf("expected combined err to contain %v, got: %v", errEl, err) | ||
} | ||
} | ||
} | ||
|
||
func TestErrorsCombineEmpty(t *testing.T) { | ||
errs := collections.Errors{} | ||
err := errs.Combine() | ||
if err != nil { | ||
t.Fatalf("expected combined err to be nil, got: %v", err) | ||
} | ||
} | ||
|
||
func TestErrorsCombineNilElements(t *testing.T) { | ||
errs := collections.Errors{nil, nil, nil} | ||
err := errs.Combine() | ||
if err != nil { | ||
t.Fatalf("expected combined err to be nil, got: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This literally never happens on a day-to-day basis, but an error can trigger under some improbable circumstances
Internally
filepath.Abs
calls thegetwd
syscall, which has quite a few possible errors : https://linux.die.net/man/3/getwdHere is a small example triggering an error on purpose : https://go.dev/play/p/JoPt8x9bQJl
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.
Ah good to know, thank you for the information!
I think I am okay with how I'm handling this for now then; if it was able to collect that path in the first place up until this point, then failing
getwd
doesn't necessarily mean the program can't eventually read that file from the relative path it currently has. So logging the error and moving on will at least notify the user that if they expect that path to be excluded, something unexpected went wrong.(I probably should have thrown a newline on that log though...)