{"record":{"id":"31313217f1b22a29","repo":"langgenius/dify","slug":"usagemissingarg-313132","errorCode":"UsageMissingArg","errorMessage":"--domain is required (no TTY); known hosts: ${hosts.join(', ')}","messagePattern":"--domain is required \\(no TTY\\); known hosts: (.+?)","errorType":"error_code","errorClass":"BaseError","httpStatus":null,"severity":"error","filePath":"cli/src/commands/use/host/use-host.ts","lineNumber":40,"sourceCode":"  if (!hosts.includes(target)) {\n    throw new BaseError({\n      code: ErrorCode.UsageInvalidFlag,\n      message: `unknown host \"${target}\"; known hosts: ${hosts.join(', ')}`,\n    })\n  }\n\n  reg.setHost(target)\n  await reg.save()\n  opts.io.out.write(`${cs.successIcon()} Active host is now ${target}\\n`)\n}\n\nasync function pickHost(\n  opts: UseHostOptions,\n  reg: Registry,\n  hosts: readonly string[],\n): Promise<string> {\n  if (!opts.io.isErrTTY) {\n    throw new BaseError({\n      code: ErrorCode.UsageMissingArg,\n      message: `--domain is required (no TTY); known hosts: ${hosts.join(', ')}`,\n    })\n  }\n  const choices: HostChoice[] = hosts.map((h) => ({\n    host: h,\n    accounts: Object.keys(reg.hosts[h]?.accounts ?? {}).length,\n    active: reg.current_host === h,\n  }))\n  const picked = await selectFromList<HostChoice>({\n    io: opts.io,\n    items: choices,\n    header: 'Select a host',\n    render: (c) =>\n      `${c.active ? '* ' : '  '}${c.host}  (${c.accounts} account${c.accounts === 1 ? '' : 's'})`,\n  })\n  return picked.host\n}","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/cli/src/commands/use/host/use-host.ts#L22-L58","documentation":"Thrown by `pickHost` (use/host/use-host.ts:40) as `usage_missing_arg` (exit 2) when no `--domain` was given AND stderr is not a TTY (non-interactive context), so the interactive host picker cannot run. The message lists known hosts. Mirrors error 37 but for host selection. Fires only on the no-TTY branch.","triggerScenarios":"Running `difyctl use host` (no `--domain`) inside a pipe, CI, cron, or any non-TTY context. The interactive `selectFromList` is unreachable and the missing-arg error is raised.","commonSituations":"CI/automation scripts omitting `--domain`; piping output; SSH without TTY; containers without `-it`.","solutions":["Pass `--domain <host>` explicitly in non-interactive contexts.","Allocate a TTY for interactive selection (`ssh -t`, `docker run -it`).","In scripts, resolve the host programmatically and always pass the flag."],"exampleFix":"// before\n$ difyctl use host < script.sh\n// after\n$ difyctl use host --domain api.dify.example < script.sh","handlingStrategy":"validation","validationCode":"// In non-interactive contexts, require --domain up front.\nfunction requireHostForNonTty(isTty: boolean, host?: string): void {\n  if (!isTty && !host) throw new Error('--domain is required when not a TTY')\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass `--domain <host>` in CI, pipes, and scripts.","Detect TTY in your wrapper and fail fast if absent.","Allocate a TTY only if interactive host selection is intended."],"tags":["cli","auth","hosts","non-interactive","missing-arg","difyctl","typescript"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}