You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(codeintel): improve upload error hints for auth and permission failures
When upload of a scip index fails, the error message may be misleading or incomplete. The complexity comes from two aspects. First that we have 2 tokens - sourcegraph access token and code host token. This PR makes sure that whenever a token is invalid we get most probable causes. Second part is that even if a token is valid on its own, the user may not have sufficient permission. sourcegraph/sourcegraph#10077 makes the error codes and messages more consistent on the server side. This way user gets a hint if token was wrong or there was a permission problem.
To summarise. First of all user gets error message from the server which often is specific (ex. upload failed: must provide gitlab_token). However basing text returned by the server (server does not return structured response like JSON) is IMO fragile so except this error message user gets hints about possible problems.
I believe those two together should eliminate confusion and point user in the right direction how to remediate the issue. We also always show the link to the documentation.
Additionally existing code was deducing used code host based on the repository URL hostname, here we also check the specified command line parameter. Those hints which are displayed to the user is not a new invention, those were just improved to provide user with more accurate information and to utilise information from the server which effectively is best source of truth what the problem was.
return"The provided Sourcegraph access token does not match the expected format (sgp_<40 hex chars> or sgp_<instance-id>_<40 hex chars>). Was it copied incorrectly or truncated?"
278
287
}
279
-
} else {
280
-
actionableHints=append(actionableHints,
281
-
"Verification is supported for the following code hosts: github.com, gitlab.com.",
282
-
"Please request support for additional code host verification at https://github.com/sourcegraph/sourcegraph/issues/4967.",
283
-
)
288
+
return"The Sourcegraph access token may be invalid, expired, or you may be connecting to the wrong Sourcegraph instance."
289
+
}
290
+
ifisForbidden {
291
+
return"You may not have sufficient permissions on this Sourcegraph instance."
// gitHubTokenHint returns a hint about the GitHub token.
308
+
// Only called when gitHubToken is set or repo starts with "github.com".
309
+
funcgitHubTokenHint(isUnauthorizedbool) string {
310
+
ifcodeintelUploadFlags.gitHubToken=="" {
311
+
returnfmt.Sprintf("No -github-token was provided. If this Sourcegraph instance enforces code host authentication, retry with -github-token=<token> for a token with access to %s.", codeintelUploadFlags.repo)
312
+
}
313
+
ifisUnauthorized {
314
+
return"The supplied -github-token may be invalid."
315
+
}
316
+
return"The supplied -github-token may lack the required permissions."
296
317
}
297
318
298
-
funcmergeStringSlices(ss...[]string) []string {
299
-
varcombined []string
300
-
for_, s:=rangess {
301
-
combined=append(combined, s...)
319
+
// gitLabTokenHint returns a hint about the GitLab token.
320
+
// Only called when gitLabToken is set or repo starts with "gitlab.com".
321
+
funcgitLabTokenHint(isUnauthorizedbool) string {
322
+
ifcodeintelUploadFlags.gitLabToken=="" {
323
+
returnfmt.Sprintf("No -gitlab-token was provided. If this Sourcegraph instance enforces code host authentication, retry with -gitlab-token=<token> for a token with access to %s.", codeintelUploadFlags.repo)
324
+
}
325
+
ifisUnauthorized {
326
+
return"The supplied -gitlab-token may be invalid."
302
327
}
328
+
return"The supplied -gitlab-token may lack the required permissions."
329
+
}
330
+
331
+
// uploadFailureReason returns the server's response body if available, or a
332
+
// generic reason derived from the HTTP status code.
0 commit comments