Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion cmd/benchpod-cli/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "+
Expand Down
9 changes: 7 additions & 2 deletions cmd/benchpod-cli/saved_connection_hint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading