@@ -217,8 +217,23 @@ func (e errorWithHint) Error() string {
217217//
218218// This method returns the error that should be passed back up to the runner.
219219func handleUploadError (accessToken string , err error ) error {
220- if errors .Is (err , upload .ErrUnauthorized ) {
221- err = attachHintsForAuthorizationError (accessToken , err )
220+ if errors .Is (err , ErrUnauthorized ) {
221+ // Extract server detail message if the error was wrapped with one
222+ // (e.g. "must provide github_token" from the upload endpoint).
223+ serverMessage := serverMessageFromError (err )
224+ if serverMessage != "" {
225+ err = errorWithHint {
226+ err : errors .Newf ("upload rejected by server: %s" , serverMessage ),
227+ hint : "For more details, see https://docs.sourcegraph.com/cli/references/code-intel/upload." ,
228+ }
229+ } else {
230+ err = attachHintsForAuthorizationError (accessToken , err )
231+ }
232+ } else if strings .Contains (err .Error (), "unexpected status code: 403" ) {
233+ err = errorWithHint {
234+ err : err ,
235+ hint : "For more details, see https://docs.sourcegraph.com/cli/references/code-intel/upload." ,
236+ }
222237 }
223238
224239 if codeintelUploadFlags .ignoreUploadFailures {
@@ -230,6 +245,21 @@ func handleUploadError(accessToken string, err error) error {
230245 return err
231246}
232247
248+ // serverMessageFromError extracts the detail string from a wrapped ErrUnauthorized.
249+ // Returns "" if the error is the bare sentinel (no server message).
250+ func serverMessageFromError (err error ) string {
251+ msg := err .Error ()
252+ sentinel := ErrUnauthorized .Error ()
253+ if msg == sentinel {
254+ return ""
255+ }
256+ // errors.Wrap produces "detail: sentinel", so strip the suffix.
257+ if strings .HasSuffix (msg , ": " + sentinel ) {
258+ return strings .TrimSuffix (msg , ": " + sentinel )
259+ }
260+ return ""
261+ }
262+
233263func attachHintsForAuthorizationError (accessToken string , originalError error ) error {
234264 var actionableHints []string
235265
@@ -303,3 +333,5 @@ func mergeStringSlices(ss ...[]string) []string {
303333
304334 return combined
305335}
336+
337+
0 commit comments