Preserve SSO guidance in concise terminal errors (#203) · github/gh-actions-lock@817f1d4 · GitHub
Skip to content

Commit 817f1d4

Browse files
Preserve SSO guidance in concise terminal errors (#203)
Keep SAML authorization instructions and SSO fallback guidance when shortening HTTP errors, without printing request URLs. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent dacafb7 commit 817f1d4

3 files changed

Lines changed: 192 additions & 3 deletions

File tree

‎cmd/gh-actions-lock/run_test.go‎

Lines changed: 102 additions & 0 deletions

‎internal/ghapi/brief.go‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
package ghapi
22

33
import (
4+
"errors"
45
"fmt"
56
"net/http"
7+
8+
"github.com/cli/go-gh/v2/pkg/api"
69
)
710

8-
// Brief formats err for one terminal line: an HTTP failure as its status
9-
// alone, without the request URL. The run log and --json keep the full error.
11+
// Brief omits HTTP request URLs and keeps authorization guidance, shortening
12+
// other HTTP failures to their status. The run log and --json keep the full error.
1013
func Brief(err error) string {
14+
var ssoErr *SSORateLimitedError
15+
if errors.As(err, &ssoErr) {
16+
return ssoErr.Error()
17+
}
1118
if code, ok := StatusCode(err); ok {
12-
return fmt.Sprintf("GitHub returned %d %s", code, http.StatusText(code))
19+
msg := fmt.Sprintf("GitHub returned %d %s", code, http.StatusText(code))
20+
var httpErr *api.HTTPError
21+
if IsSAMLEnforcement(err) && errors.As(err, &httpErr) {
22+
msg += ": " + httpErr.Message
23+
}
24+
return msg
1325
}
1426
return err.Error()
1527
}

‎internal/ghapi/brief_test.go‎

Lines changed: 75 additions & 0 deletions

0 commit comments

Comments
 (0)