diff --git a/cmd/bd/sync.go b/cmd/bd/sync.go index bd2c97311..6eff49c95 100644 --- a/cmd/bd/sync.go +++ b/cmd/bd/sync.go @@ -915,11 +915,28 @@ func syncFailureText(err error) string { return "" } if line := sshDialTimeoutLine.FindString(err.Error()); line != "" { - return "SSH remote could not be reached (dial timed out): " + scrubURLCredentials(strings.TrimSpace(line)) + return syncFailureStep(err, line) + "SSH remote could not be reached (dial timed out): " + scrubURLCredentials(strings.TrimSpace(line)) } return err.Error() } +// syncFailureStep returns err's outermost wrap segment for the dial-timeout +// rewrite to keep: runSyncLoop's "pull: " or "push: " step, which is how an +// operator tells whether local work already reached the remote. A segment +// that contains the dial line is git output folded into the wrap +// (cliTransferError), auth hints and all, so it yields "" instead. +func syncFailureStep(err error, line string) string { + inner := errors.Unwrap(err) + if inner == nil { + return "" + } + prefix, ok := strings.CutSuffix(err.Error(), inner.Error()) + if !ok || strings.Contains(prefix, line) { + return "" + } + return scrubURLCredentials(prefix) +} + // mergeBlockersOp builds the loop's positive constraint-violation hook, or nil // when this store cannot answer the question — an unimplemented interface // must leave the detector silent, never guessing. Bound to the same st the diff --git a/cmd/bd/sync_test.go b/cmd/bd/sync_test.go index 1acd6ff9d..f8e57bd2c 100644 --- a/cmd/bd/sync_test.go +++ b/cmd/bd/sync_test.go @@ -34,6 +34,25 @@ func TestSyncFailureTextDistinguishesSSHDialTimeoutFromAuth(t *testing.T) { t.Errorf("dial timeout retained auth hint %q: %q", misleading, got) } } + // The rewrite must keep runSyncLoop's step: pull vs push is what tells an + // operator whether local work already reached the remote. A wrap segment + // that itself embeds git's output (cliTransferError's shape) is not a step + // and must not come back, auth hints and all. + explained := "SSH remote could not be reached (dial timed out): " + timeoutLine + cliTransfer := fmt.Errorf("dolt push failed: %s: %w", gitText, errors.New("exit status 1")) + for _, tc := range []struct { + name string + err error + want string + }{ + {"pull step", timeout, "pull: " + explained}, + {"push step over a CLI transfer", fmt.Errorf("push: %w", cliTransfer), "push: " + explained}, + {"bare CLI transfer", cliTransfer, explained}, + } { + if got := syncFailureText(tc.err); got != tc.want { + t.Errorf("%s: got %q, want %q", tc.name, got, tc.want) + } + } auth := fmt.Errorf("pull: %w", errors.New("git@host: Permission denied (publickey).\nhint: run `ssh-add ` to pre-load your key for SSH remotes")) if got := syncFailureText(auth); got != auth.Error() {