{"record":{"id":"dee1a28f2965959c","repo":"jackwener/OpenCLI","slug":"input-required-slug-or-uuid","errorCode":null,"errorMessage":"input required: slug or UUID","messagePattern":"input required: slug or UUID","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/slock/server-use.js","lineNumber":21,"sourceCode":"import { ArgumentError } from '@jackwener/opencli/errors';\nimport { dispatchEvaluateResult } from './errors.js';\nimport { SLOCK_SITE, SLOCK_DOMAIN, SLOCK_HOME_URL, SLOCK_API_BASE } from './shared.js';\nimport { UUID_RE } from './resolve.js';\n\ncli({\n  site: SLOCK_SITE,\n  name: 'server-use',\n  access: 'write',\n  description: 'Set the active slock server (writes localStorage.slock_last_server_slug)',\n  domain: SLOCK_DOMAIN,\n  strategy: Strategy.COOKIE,\n  browser: true,\n  siteSession: 'persistent',\n  args: [{ name: 'input', positional: true, required: true, help: 'server slug, \"#slug\", or UUID id' }],\n  columns: ['id', 'slug', 'name', 'written'],\n  func: async (page, kwargs) => {\n    const raw = String(kwargs.input ?? '').trim();\n    if (!raw) throw new ArgumentError('input required: slug or UUID');\n    const isUuid = UUID_RE.test(raw);\n    const slug = raw.replace(/^#/, '').toLowerCase();\n    const slugJson = JSON.stringify(slug);\n    await page.goto(SLOCK_HOME_URL);\n    const snippet = `\n      const token = localStorage.getItem('slock_access_token');\n      if (!token) return { kind: 'auth', detail: 'no token' };\n      const res = await fetch('${SLOCK_API_BASE}/servers/', { credentials:'include', headers:{authorization:'Bearer '+token,accept:'application/json'} });\n      if (!res.ok) return { kind: res.status===401?'auth':'http', status: res.status, where:'/servers/' };\n      const list = await res.json();\n      const arr = Array.isArray(list) ? list : (list.servers || list.data || []);\n      let hit;\n      if (${isUuid}) hit = arr.find((s) => s.id === ${JSON.stringify(raw)});\n      else hit = arr.find((s) => (s.slug || '').toLowerCase() === ${slugJson});\n      if (!hit) {\n        const choices = arr.map((s) => s.slug).filter(Boolean).join(', ');\n        return { kind: 'unresolvable', detail: 'no server matches ' + ${JSON.stringify(raw)} + '. Known slugs: ' + choices };\n      }","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/slock/server-use.js#L3-L39","documentation":"The command's positional `input` argument is required; the func trims the raw string and throws ArgumentError when it is empty. Acceptable input is a server slug, a '#slug', or a UUID id.","triggerScenarios":"Running `server-use` with no positional argument, or with a value that is only whitespace (spaces/tabs), so String(...).trim() yields ''.","commonSituations":"Forgetting the argument in a scripted call; a shell variable holding an empty string due to a failed lookup (`SERVER=\"\" server-use $SERVER`); quoting mistakes that pass an empty string.","solutions":["Supply the server slug, #slug, or UUID as the positional argument, e.g. `server-use my-server`.","Check the shell variable you pass actually contains a value (`echo \"$SERVER\"`).","Run the command without arguments first to see usage/help for the accepted input forms."],"exampleFix":"// before\nspawn('slock', ['server-use', serverName ?? '']);\n// after\nif (!serverName) throw new Error('server name not configured');\nspawn('slock', ['server-use', serverName]);","handlingStrategy":"validation","validationCode":"const input = String(process.argv[3] ?? '').trim();\nif (!input) {\n  console.error('usage: server-use <slug | #slug | uuid>');\n  process.exit(2);\n}","typeGuard":"const hasServerInput = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try {\n  await cli('server-use', input);\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.startsWith('input required')) {\n    console.error('Provide a server slug or UUID, e.g. server-use my-server');\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Check required shell variables are non-empty before invoking (${VAR:?msg}).","Quote arguments to avoid empty-string expansion.","Keep the active-server value in config so you never call server-use blindly."],"tags":["cli","missing-argument","input-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}