{"record":{"id":"1a5cb89459463f50","repo":"langgenius/dify","slug":"usageinvalidflag-1a5cb8","errorCode":"UsageInvalidFlag","errorMessage":"unknown account \"${target}\" on ${host}; known: ${emails.join(', ')}","messagePattern":"unknown account \"(.+?)\" on (.+?); known: (.+?)","errorType":"error_code","errorClass":"BaseError","httpStatus":null,"severity":"error","filePath":"cli/src/commands/use/account/use-account.ts","lineNumber":33,"sourceCode":"  readonly store?: TokenStore\n}\n\ntype AccountChoice = { email: string; name: string; sso: boolean; active: boolean }\n\nconst USE_HOST_HINT = \"run 'difyctl use host' or 'difyctl auth login'\"\n\nexport async function runUseAccount(opts: UseAccountOptions): Promise<void> {\n  const cs = colorScheme(colorEnabled(opts.io.isErrTTY))\n  const reg = await Registry.load()\n  if (reg.current_host === undefined) throw notLoggedInError(USE_HOST_HINT)\n  const host = reg.current_host\n  const entry = reg.hosts[host]\n  if (entry === undefined) throw notLoggedInError(USE_HOST_HINT)\n\n  const emails = Object.keys(entry.accounts)\n  const target = opts.email ?? (await pickAccount(opts, entry, host))\n  if (!emails.includes(target)) {\n    throw new BaseError({\n      code: ErrorCode.UsageInvalidFlag,\n      message: `unknown account \"${target}\" on ${host}; known: ${emails.join(', ')}`,\n    })\n  }\n\n  const store = opts.store ?? getTokenStore(reg.token_storage)\n  if ((await store.read(host, target)) === '') {\n    throw new BaseError({\n      code: ErrorCode.NotLoggedIn,\n      message: `no credential stored for ${target} on ${host}`,\n      hint: `run 'difyctl auth login --host ${host}'`,\n    })\n  }\n\n  reg.setAccount(target)\n  await reg.save()\n  opts.io.out.write(`${cs.successIcon()} Active account on ${host} is now ${target}\\n`)\n}","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/cli/src/commands/use/account/use-account.ts#L15-L51","documentation":"Thrown by `runUseAccount` (use/account/use-account.ts:33) as `usage_invalid_flag` (exit 2) when the resolved `--email` target is not among the accounts registered for the current host in the local Registry. The message lists all known emails for that host to aid correction. Fires after host validation but before credential lookup.","triggerScenarios":"Running `difyctl use account --email wrong@example.com` (or selecting an email not in the registry) on a host where that email was never logged in. `emails.includes(target)` is false at line 32.","commonSituations":"Typo in the email; using the wrong host's account list; the account was logged in on a different host; SSO email differs from the typed one; registry out of date.","solutions":["Pick an email from the message's `known:` list.","If the intended account is missing, log in on this host: `difyctl auth login --host <host>`.","Switch to the correct host first: `difyctl use host <host>`."],"exampleFix":"// before\n$ difyctl use account --email wrong@example.com\n// after\n$ difyctl use account --email alice@example.com","handlingStrategy":"validation","validationCode":"const reg = await Registry.load()\nconst emails = Object.keys(reg.hosts[host]?.accounts ?? {})\nfunction isKnownAccount(email: string): boolean {\n  return emails.includes(email)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Choose the email from the registry's known list for the current host.","Log in on the host first if the account is missing: `difyctl auth login --host <host>`.","Switch to the correct host with `difyctl use host` before selecting an account."],"tags":["cli","auth","accounts","registry","difyctl","typescript"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}