{"record":{"id":"700f0e989af92dd2","repo":"AlistGo/alist","slug":"unsupported-credential-state-d","errorCode":null,"errorMessage":"unsupported credential state: %d","messagePattern":"unsupported credential state: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"drivers/139/util.go","lineNumber":1272,"sourceCode":"\tcase credentialStateAuthorization:\n\t\tlog.Debugf(\"139yun: Authorization exists, skipping initialization login.\")\n\t\treturn nil\n\tcase credentialStateFullLogin, credentialStateCookiesOnly:\n\t\tlog.Infof(\"139yun: Authorization missing, attempting login...\")\n\t\tif d.tryFastLoginWithCookies() {\n\t\t\treturn nil\n\t\t}\n\t\tif state == credentialStateCookiesOnly {\n\t\t\treturn fmt.Errorf(\"fast login with cookies failed, and cannot fallback to password login (missing username/password)\")\n\t\t}\n\t\tlog.Infof(\"139yun: fast login failed or not possible, performing full password login (Step 1).\")\n\t\t_, err := d.loginWithPassword()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"login with password failed: %w\", err)\n\t\t}\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported credential state: %d\", state)\n\t}\n}\n\nfunc (d *Yun139) credentialState() (credentialState, error) {\n\td.Authorization = strings.TrimSpace(d.Authorization)\n\td.Username = strings.TrimSpace(d.Username)\n\td.MailCookies = strings.TrimSpace(d.MailCookies)\n\n\tif d.Authorization != \"\" {\n\t\tif strings.HasPrefix(strings.ToLower(d.Authorization), \"basic \") {\n\t\t\treturn 0, fmt.Errorf(\"authorization should not include Basic prefix\")\n\t\t}\n\t\treturn credentialStateAuthorization, nil\n\t}\n\n\tif d.MailCookies != \"\" && !hasCookiePair(d.MailCookies) {\n\t\treturn 0, fmt.Errorf(\"MailCookies format is invalid, please check your configuration\")\n\t}","sourceCodeStart":1254,"sourceCodeEnd":1290,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/139/util.go#L1254-L1290","documentation":"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.","triggerScenarios":"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.","commonSituations":"Developers patching the driver locally and adding a state; users essentially never see it.","solutions":["If you modified the driver, make the switch cover your new state (or convert to exhaustive checking)","Update/rebuild from clean upstream sources to eliminate a stale or half-applied patch","If it appears in an unmodified build, report as a driver bug with the state number printed in the message"],"exampleFix":"// before\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported credential state: %d\", state)\n// after (compile-time exhaustiveness)\n\tswitch state {\n\tcase credentialStateAuthorization:\n\t\t...\n\tcase credentialStateFullLogin, credentialStateCookiesOnly:\n\t\t...\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"unhandled credential state: %d\", state))\n\t}","handlingStrategy":"type-guard","validationCode":"// If you extend the state enum, assert coverage at init time\nif state < 0 || state > credentialStateMax {\n\treturn fmt.Errorf(\"credential state out of range: %d\", state)\n}","typeGuard":"func isValidCredentialState(s credentialState) bool {\n\treturn s == credentialStateAuthorization || s == credentialStateFullLogin || s == credentialStateCookiesOnly\n}","tryCatchPattern":"// Defensive: report the numeric state for debugging; users cannot fix this\nif err != nil && strings.Contains(err.Error(), \"unsupported credential state\") {\n\tlog.Printf(\"driver bug: report state number %s upstream\", err)\n}","preventionTips":["When adding a credential state locally, update every switch over it in the same commit","Use exhaustive linters (e.g. go exhaustive switch checks) in CI for this driver"],"tags":["internal","defensive","unreachable"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}