bytebase/bytebase · error

failed to test auth, error: %v

Error message

failed to test auth, error: %v

What it means

Slack's auth.test responded 200 with parseable JSON but ok:false, meaning Slack rejected the token. The surfaced Slack error string (e.g. invalid_auth, account_inactive, token_revoked) identifies why. This is the definitive signal that the configured Slack bot token is not usable.

Source

Thrown at backend/plugin/webhook/slack/app.go:87

	if err != nil {
		return errors.Wrapf(err, "failed to send request")
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		return errors.Errorf("received non-200 status code %d", resp.StatusCode)
	}

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return errors.Wrapf(err, "failed to read body")
	}
	var res authTestResponse
	if err := json.Unmarshal(body, &res); err != nil {
		return errors.Wrapf(err, "failed to unmarshal")
	}
	if !res.OK {
		return errors.Errorf("failed to test auth, error: %v", res.Error)
	}

	scopes := resp.Header.Get("x-oauth-scopes")
	hasScope := map[string]bool{}
	for _, s := range strings.Split(scopes, ",") {
		hasScope[s] = true
	}
	var missScope []string
	for _, s := range []string{"users:read", "users:read.email", "channels:manage", "groups:write", "im:write", "chat:write", "mpim:write"} {
		if !hasScope[s] {
			missScope = append(missScope, s)
		}
	}
	if len(missScope) > 0 {
		return errors.Errorf("missing the following scopes: %s", strings.Join(missScope, ","))
	}

	return nil

View on GitHub (pinned to 1870550677)

Solutions

  1. Read the Slack error in the message: invalid_auth/token_revoked means regenerate the token; account_inactive means the account/bot was disabled.
  2. Create/copy a fresh bot token from the Slack app's OAuth & Permissions page (xoxb-...) and update the Bytebase webhook configuration.
  3. Reinstall the Slack app to the workspace if it was uninstalled or scopes changed.
  4. Confirm required chat:write scope is present in the token's scopes (the code also checks x-oauth-scopes).
  5. Re-run the connection test in Bytebase after updating the token.

Example fix

// before
"token": "xoxb-1234-old-revoked-token"
// after: fresh token from Slack app config
"token": "xoxb-5678-9012-current-valid-token"
Defensive patterns

Strategy: validation

Validate before calling

// validate the token before storing it
req, _ := http.NewRequest("POST", "https://slack.com/api/auth.test", nil)
req.Header.Set("Authorization", "Bearer "+token)
resp, err := http.DefaultClient.Do(req)
if err != nil { return err }
var r struct{ OK bool `json:"ok"`; Error string `json:"error"` }
json.NewDecoder(resp.Body).Decode(&r)
if !r.OK { return fmt.Errorf("token rejected by Slack: %s", r.Error) }

Type guard

func tokenUsable(res authTestResponse) bool {
    return res.OK
}

Try / catch

if err := p.authTest(ctx); err != nil {
    if strings.Contains(err.Error(), "invalid_auth") || strings.Contains(err.Error(), "token_revoked") {
        // surface 're-enter Slack bot token' to the user
    } else if strings.Contains(err.Error(), "account_inactive") {
        // surface 'reinstall the Slack app'
    }
}

Prevention

When it happens

Trigger: authTest reads res.OK == false after a successful call — token invalid/deleted, bot app uninstalled, workspace deactivated, or token type lacking required scopes (subsequent scope check on x-oauth-scopes can also gate access).

Common situations: Token rotated/revoked in Slack admin console but old value still stored in Bytebase config; bot app removed from the workspace; pasting a user token (xoxp) where a bot token (xoxb) is required; Slack app not reinstalled after scope changes.

Related errors


AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06). Data as JSON: /api/errors/0c7dbfe22e933952. Report an issue: GitHub.