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

refactor: replace error-handling code for potential wrapped errors #20214

Merged
merged 6 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crypto/keys/secp256k1/internal/secp256k1/secp256_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"crypto/elliptic"
"crypto/rand"
"encoding/hex"
"errors"
"io"
"testing"
)
Expand Down Expand Up @@ -93,7 +94,7 @@ func TestInvalidRecoveryID(t *testing.T) {
sig, _ := Sign(msg, seckey)
sig[64] = 99
_, err := RecoverPubkey(msg, sig)
if err != ErrInvalidRecoveryID {
if !errors.Is(err, ErrInvalidRecoveryID) {
t.Fatalf("got %q, want %q", err, ErrInvalidRecoveryID)
}
}
Expand Down
3 changes: 2 additions & 1 deletion x/group/internal/orm/table_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package orm

import (
"errors"
"fmt"
"testing"

Expand Down Expand Up @@ -231,7 +232,7 @@ func TestDelete(t *testing.T) {

// then
var loaded testdata.TableModel
if spec.expErr == sdkerrors.ErrNotFound {
if errors.Is(spec.expErr, sdkerrors.ErrNotFound) {
require.NoError(t, myTable.GetOne(store, EncodeSequence(1), &loaded))
assert.Equal(t, initValue, loaded)
} else {
Expand Down
3 changes: 2 additions & 1 deletion x/upgrade/plan/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func DownloadUpgrade(dstRoot, url, daemonName string) error {
// First try to download it as a single file. If there's no error, it's okay and we're done.
if err := getFile(url, target); err != nil {
// If it was a checksum error, no need to try as directory.
if _, ok := err.(*getter.ChecksumError); ok {
var checksumError *getter.ChecksumError
if errors.As(err, &checksumError) {
Comment on lines +33 to +34
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace direct return of err with a more descriptive error or handle it differently after type assertion with errors.As.

- return err
+ return fmt.Errorf("checksum error: %w", err)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
var checksumError *getter.ChecksumError
if errors.As(err, &checksumError) {
var checksumError *getter.ChecksumError
if errors.As(err, &checksumError) {
return fmt.Errorf("checksum error: %w", err)

return err
}
// File download didn't work, try it as an archive.
Expand Down
Loading