AlistGo/alist · warning

unsupported credential state: %d

Error message

unsupported credential state: %d

What it means

A defensive default branch in the login initialization switch: credentialState() returned a numeric state value that the switch does not handle. In the current code every produced state (authorization, fullLogin, cookiesOnly) plus the error path is covered, so hitting this means an out-of-sync state enum (new state added without updating this switch) or memory corruption — effectively unreachable in practice.

Source

Thrown at drivers/139/util.go:1272

	case credentialStateAuthorization:
		log.Debugf("139yun: Authorization exists, skipping initialization login.")
		return nil
	case credentialStateFullLogin, credentialStateCookiesOnly:
		log.Infof("139yun: Authorization missing, attempting login...")
		if d.tryFastLoginWithCookies() {
			return nil
		}
		if state == credentialStateCookiesOnly {
			return fmt.Errorf("fast login with cookies failed, and cannot fallback to password login (missing username/password)")
		}
		log.Infof("139yun: fast login failed or not possible, performing full password login (Step 1).")
		_, err := d.loginWithPassword()
		if err != nil {
			return fmt.Errorf("login with password failed: %w", err)
		}
		return nil
	default:
		return fmt.Errorf("unsupported credential state: %d", state)
	}
}

func (d *Yun139) credentialState() (credentialState, error) {
	d.Authorization = strings.TrimSpace(d.Authorization)
	d.Username = strings.TrimSpace(d.Username)
	d.MailCookies = strings.TrimSpace(d.MailCookies)

	if d.Authorization != "" {
		if strings.HasPrefix(strings.ToLower(d.Authorization), "basic ") {
			return 0, fmt.Errorf("authorization should not include Basic prefix")
		}
		return credentialStateAuthorization, nil
	}

	if d.MailCookies != "" && !hasCookiePair(d.MailCookies) {
		return 0, fmt.Errorf("MailCookies format is invalid, please check your configuration")
	}

View on GitHub (pinned to 843d9dc814)

Solutions

  1. If you modified the driver, make the switch cover your new state (or convert to exhaustive checking)
  2. Update/rebuild from clean upstream sources to eliminate a stale or half-applied patch
  3. If it appears in an unmodified build, report as a driver bug with the state number printed in the message

Example fix

// before
	default:
		return fmt.Errorf("unsupported credential state: %d", state)
// after (compile-time exhaustiveness)
	switch state {
	case credentialStateAuthorization:
		...
	case credentialStateFullLogin, credentialStateCookiesOnly:
		...
	default:
		panic(fmt.Sprintf("unhandled credential state: %d", state))
	}
Defensive patterns

Strategy: type-guard

Validate before calling

// If you extend the state enum, assert coverage at init time
if state < 0 || state > credentialStateMax {
	return fmt.Errorf("credential state out of range: %d", state)
}

Type guard

func isValidCredentialState(s credentialState) bool {
	return s == credentialStateAuthorization || s == credentialStateFullLogin || s == credentialStateCookiesOnly
}

Try / catch

// Defensive: report the numeric state for debugging; users cannot fix this
if err != nil && strings.Contains(err.Error(), "unsupported credential state") {
	log.Printf("driver bug: report state number %s upstream", err)
}

Prevention

When it happens

Trigger: Only if a new credentialState constant is added to credentialState() without extending this switch in initLogin/whatever wraps it; not producible by any user configuration.

Common situations: Developers patching the driver locally and adding a state; users essentially never see it.

Related errors


AI-assisted analysis of AlistGo/alist@843d9dc814 (2026-08-15). Data as JSON: /api/errors/700f0e989af92dd2. Report an issue: GitHub.