diff --git a/cmd/benchpod-cli/errors.go b/cmd/benchpod-cli/errors.go index 1d0cf65..1830ee0 100644 --- a/cmd/benchpod-cli/errors.go +++ b/cmd/benchpod-cli/errors.go @@ -150,7 +150,9 @@ func withRefusalHint(err error) error { // saved default (saved, "" when the run did not use it): after a pod is unplugged or another pod // takes its place, that default is stale and only `discover` / `set-connection` fix it. func withSavedConnectionHint(err error, saved string) error { - if saved == "" || !errors.Is(err, tcpclient.ErrUnreachable) { + // Only when it is the saved address that did not answer: a command that read the default and + // then went another way (flash-self over USB DFU, say) fails for its own reasons. + if saved == "" || !errors.Is(err, tcpclient.ErrUnreachable) || !strings.Contains(err.Error(), saved) { return err } return fmt.Errorf("%w\n%s is the saved default connection. If that pod is unplugged or you use another one, "+ diff --git a/cmd/benchpod-cli/saved_connection_hint_test.go b/cmd/benchpod-cli/saved_connection_hint_test.go index 93a9477..0dac519 100644 --- a/cmd/benchpod-cli/saved_connection_hint_test.go +++ b/cmd/benchpod-cli/saved_connection_hint_test.go @@ -12,19 +12,24 @@ import ( // An unreachable pod at the saved default says the address is the saved one and how to change it; // an address the user passed, or another error, is left as it is. func TestSavedConnectionHint(t *testing.T) { - dial := fmt.Errorf("status: %w", tcpclient.ErrUnreachable) + dial := fmt.Errorf("status: connect to pod at 10.237.8.85:8080: %w", tcpclient.ErrUnreachable) got := withSavedConnectionHint(dial, "10.237.8.85:8080").Error() for _, want := range []string{"pod unreachable", "10.237.8.85:8080 is the saved default connection", "benchpod discover", "set-connection"} { if !strings.Contains(got, want) { t.Errorf("missing %q in %q", want, got) } } - if !errors.Is(withSavedConnectionHint(dial, "x"), tcpclient.ErrUnreachable) { + if !errors.Is(withSavedConnectionHint(dial, "10.237.8.85:8080"), tcpclient.ErrUnreachable) { t.Error("the hint must keep the error's identity (exit code)") } if got := withSavedConnectionHint(dial, ""); got != dial { t.Errorf("no saved default used: %v", got) } + // The default was read, but what failed was another path (flash-self's USB console): no hint. + usb := fmt.Errorf("no USB ports found: %w", tcpclient.ErrUnreachable) + if got := withSavedConnectionHint(usb, "10.237.8.85:8080"); got != usb { + t.Errorf("another path failed: %v", got) + } other := errors.New("refused: busy") if got := withSavedConnectionHint(other, "10.0.0.1:8080"); got != other { t.Errorf("not unreachable: %v", got)