From 24497af6b12e62f6d4de0aed3144de3101f55d34 Mon Sep 17 00:00:00 2001 From: gammazero <11790789+gammazero@users.noreply.github.com> Date: Wed, 17 Dec 2025 21:18:23 -1000 Subject: [PATCH 1/3] keys: skip bad keys when listing Change the `ipfs key list` behavior to log an error and continue listing keys when a key cannot be read from the keystore or decoded. Closes: #11102 --- core/commands/keystore.go | 4 ++-- core/coreapi/key.go | 17 ++++++++++------- docs/changelogs/v0.40.md | 7 ++++++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/core/commands/keystore.go b/core/commands/keystore.go index 0ffd14189..6ce1b5a0d 100644 --- a/core/commands/keystore.go +++ b/core/commands/keystore.go @@ -458,7 +458,7 @@ var keyListCmd = &cmds.Command{ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.OptionIPNSBase.Name()].(string)) if err != nil { - return err + return fmt.Errorf("cannot get key encoder: %w", err) } api, err := cmdenv.GetApi(env, req) @@ -468,7 +468,7 @@ var keyListCmd = &cmds.Command{ keys, err := api.Key().List(req.Context) if err != nil { - return err + return fmt.Errorf("listing keys failed: %w", err) } list := make([]KeyOutput, 0, len(keys)) diff --git a/core/coreapi/key.go b/core/coreapi/key.go index 784045d26..e779c773f 100644 --- a/core/coreapi/key.go +++ b/core/coreapi/key.go @@ -29,7 +29,7 @@ type key struct { func newKey(name string, pid peer.ID) (*key, error) { p, err := path.NewPath("/ipns/" + ipns.NameFromPeer(pid).String()) if err != nil { - return nil, err + return nil, fmt.Errorf("cannot create new key: %w", err) } return &key{ name: name, @@ -121,34 +121,37 @@ func (api *KeyAPI) List(ctx context.Context) ([]coreiface.Key, error) { keys, err := api.repo.Keystore().List() if err != nil { - return nil, err + return nil, fmt.Errorf("cannot list keys in keystore: %w", err) } sort.Strings(keys) - out := make([]coreiface.Key, len(keys)+1) + out := make([]coreiface.Key, 1, len(keys)+1) out[0], err = newKey("self", api.identity) if err != nil { return nil, err } - for n, k := range keys { + for _, k := range keys { privKey, err := api.repo.Keystore().Get(k) if err != nil { - return nil, err + log.Errorf("cannot get key from keystore: %s", err) + continue } pubKey := privKey.GetPublic() pid, err := peer.IDFromPublicKey(pubKey) if err != nil { - return nil, err + log.Errorf("cannot decode public key: %s", err) + continue } - out[n+1], err = newKey(k, pid) + k, err := newKey(k, pid) if err != nil { return nil, err } + out = append(out, k) } return out, nil } diff --git a/docs/changelogs/v0.40.md b/docs/changelogs/v0.40.md index 29780937f..b2d516c25 100644 --- a/docs/changelogs/v0.40.md +++ b/docs/changelogs/v0.40.md @@ -11,7 +11,8 @@ This release was brought to you by the [Shipyard](https://ipshipyard.com/) team. - [Overview](#overview) - [๐Ÿ”ฆ Highlights](#-highlights) - [Routing V1 HTTP API now exposed by default](#routing-v1-http-api-now-exposed-by-default) - - [Track total size when adding pins](#track-total-size-when-adding-pins] + - [Track total size when adding pins](#track-total-size-when-adding-pins) + - [Skip bad keys when listing](#skip_bad_keys_when_listing) - [๐Ÿ“ Changelog](#-changelog) - [๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Contributors](#-contributors) @@ -32,6 +33,10 @@ Example output: Fetched/Processed 336 nodes (83 MB) ``` +#### Skip bad keys when listing + +Change the `ipfs key list` behavior to log an error and continue listing keys when a key cannot be read from the keystore or decoded. + ### ๐Ÿ“ Changelog ### ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Contributors From c912212385601d97de0fe7a581f732996df715c6 Mon Sep 17 00:00:00 2001 From: gammazero <11790789+gammazero@users.noreply.github.com> Date: Thu, 18 Dec 2025 10:00:40 -1000 Subject: [PATCH 2/3] print output on error --- docs/examples/kubo-as-a-library/main_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/examples/kubo-as-a-library/main_test.go b/docs/examples/kubo-as-a-library/main_test.go index ec34d62b1..3dd665747 100644 --- a/docs/examples/kubo-as-a-library/main_test.go +++ b/docs/examples/kubo-as-a-library/main_test.go @@ -9,7 +9,7 @@ import ( func TestExample(t *testing.T) { out, err := exec.Command("go", "run", "main.go").Output() if err != nil { - t.Fatalf("running example (%v)", err) + t.Fatalf("running example (%v): %s", err, string(out)) } if !strings.Contains(string(out), "All done!") { t.Errorf("example did not run successfully") From a5b7d7897b5507819b1ad362a0b4527b0dcc162a Mon Sep 17 00:00:00 2001 From: gammazero <11790789+gammazero@users.noreply.github.com> Date: Fri, 19 Dec 2025 14:01:08 -1000 Subject: [PATCH 3/3] Print stderr on test failure --- docs/examples/kubo-as-a-library/main_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/examples/kubo-as-a-library/main_test.go b/docs/examples/kubo-as-a-library/main_test.go index 3dd665747..be601c6a9 100644 --- a/docs/examples/kubo-as-a-library/main_test.go +++ b/docs/examples/kubo-as-a-library/main_test.go @@ -9,7 +9,11 @@ import ( func TestExample(t *testing.T) { out, err := exec.Command("go", "run", "main.go").Output() if err != nil { - t.Fatalf("running example (%v): %s", err, string(out)) + var stderr string + if xe, ok := err.(*exec.ExitError); ok { + stderr = string(xe.Stderr) + } + t.Fatalf("running example (%v): %s\n%s", err, string(out), stderr) } if !strings.Contains(string(out), "All done!") { t.Errorf("example did not run successfully")