{"record":{"id":"19e05d91152d7201","repo":"Wei-Shaw/sub2api","slug":"priority-must-be-0","errorCode":null,"errorMessage":"priority must be >= 0","messagePattern":"priority must be >= 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/internal/handler/admin/account_data.go","lineNumber":703,"sourceCode":"\tif strings.TrimSpace(item.Type) == \"\" {\n\t\treturn errors.New(\"account type is required\")\n\t}\n\tif len(item.Credentials) == 0 {\n\t\treturn errors.New(\"account credentials is required\")\n\t}\n\tswitch item.Type {\n\tcase service.AccountTypeOAuth, service.AccountTypeSetupToken, service.AccountTypeAPIKey, service.AccountTypeUpstream:\n\tdefault:\n\t\treturn fmt.Errorf(\"account type is invalid: %s\", item.Type)\n\t}\n\tif item.RateMultiplier != nil && *item.RateMultiplier < 0 {\n\t\treturn errors.New(\"rate_multiplier must be >= 0\")\n\t}\n\tif item.Concurrency < 0 {\n\t\treturn errors.New(\"concurrency must be >= 0\")\n\t}\n\tif item.Priority < 0 {\n\t\treturn errors.New(\"priority must be >= 0\")\n\t}\n\treturn nil\n}\n\nfunc defaultProxyName(name string) string {\n\tif strings.TrimSpace(name) == \"\" {\n\t\treturn \"imported-proxy\"\n\t}\n\treturn name\n}\n\n// enrichCredentialsFromIDToken performs best-effort extraction of user info fields\n// (email, plan_type, chatgpt_account_id, etc.) from id_token in credentials.\n// Only applies to OpenAI OAuth accounts. Skips expired token errors silently.\n// Existing credential values are never overwritten — only missing fields are filled.\nfunc enrichCredentialsFromIDToken(item *DataAccount) {\n\tif item.Credentials == nil {\n\t\treturn","sourceCodeStart":685,"sourceCodeEnd":721,"githubUrl":"https://github.com/Wei-Shaw/sub2api/blob/073e92d17178a1ccdb0a27017f572f10c9c7ab62/backend/internal/handler/admin/account_data.go#L685-L721","documentation":"Thrown by the admin account import validator (validateAccountImportItem) when an imported account item has a Priority field below zero. The check runs after account-type and rate_multiplier/concurrency checks, guarding numeric sanity before accounts are persisted. It is a pure payload-validation error, not a system failure.","triggerScenarios":"POST/PUT to the admin account import endpoint with a JSON item whose priority is negative (e.g. \"priority\": -1). Also triggered by clients that model priority as a signed value and send -1 to mean 'lowest'.","commonSituations":"Bulk import scripts generated from spreadsheets containing negative numbers; UIs that allow -1 as a sentinel for 'no priority'; confusion with systems where lower number = higher priority and 0 is reserved.","solutions":["Set priority to 0 or a positive integer in the imported item and resubmit the import","Check the preceding validation errors (account type, rate_multiplier, concurrency) in the same payload — they are validated first and may also fire","If importing from CSV/JSON exports, sanitize numeric fields (clamp negatives to 0) before upload"],"exampleFix":"// before\n{\"type\": \"oauth\", \"name\": \"acct-1\", \"priority\": -1}\n// after\n{\"type\": \"oauth\", \"name\": \"acct-1\", \"priority\": 0}","handlingStrategy":"validation","validationCode":"// Go: sanitize account import items before submit\nfor i := range items {\n    if items[i].Priority < 0 { items[i].Priority = 0 }\n    if items[i].Concurrency < 0 { items[i].Concurrency = 0 }\n    if items[i].RateMultiplier != nil && *items[i].RateMultiplier < 0 { items[i].RateMultiplier = nil }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp numeric account fields to non-negative before any import call","Run imports through a dry-run/validate mode when the API offers one","Keep export→import pipelines symmetric so sentinel values like -1 never enter payloads"],"tags":["admin","validation","account-import","backend"],"backgroundTag":null,"analyzedSha":"073e92d17178a1ccdb0a27017f572f10c9c7ab62","analyzedAt":"2026-08-15T14:33:00.750Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}