{"record":{"id":"fc529eba7d0d4735","repo":"ruvnet/RuView","slug":"prompt-must-be-a-non-empty-string","errorCode":null,"errorMessage":"prompt must be a non-empty string","messagePattern":"prompt must be a non-empty string","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"harness/homecore/src/hosts/claude-code.js","lineNumber":37,"sourceCode":"    '--permission-mode',\n    write ? 'acceptEdits' : 'plan',\n    '--allowedTools',\n    write ? 'Read,Grep,Glob,Edit,Write' : 'Read,Grep,Glob',\n  ];\n}\n\nexport async function runClaudeCode({\n  prompt,\n  repoRoot,\n  trustedRoot = repoRoot,\n  allowWrite = false,\n  confirm = false,\n  command = 'claude',\n  commandArgs = [],\n  ...runOptions\n}) {\n  if (typeof prompt !== 'string' || !prompt.trim()) {\n    throw new TypeError('prompt must be a non-empty string');\n  }\n  const root = assertTrustedHomecoreRepo(repoRoot, { trustedRoot });\n  const write = allowWrite === true && confirm === true;\n  const input = `${SAFETY_PREFIX}\\n\\nUser task:\\n${prompt.trim()}`;\n  return runProcess(\n    command,\n    [...commandArgs, ...buildClaudeCodeArgs({ write })],\n    { ...runOptions, cwd: root, input },\n  );\n}\n\nexport default Object.freeze({\n  name: 'claude-code',\n  run: runClaudeCode,\n  buildArgs: buildClaudeCodeArgs,\n});\n","sourceCodeStart":19,"sourceCodeEnd":54,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/harness/homecore/src/hosts/claude-code.js#L19-L54","documentation":"The require_authentication dependency (auth.py:435) raises HTTPException 401 with WWW-Authenticate: Bearer when request.state.user is None. Like error index 14 this indicates the middleware never set the user, but as a FastAPI dependency it produces a well-formed 401 response rather than an unhandled exception.","triggerScenarios":"Using Depends(require_authentication) on an endpoint while AuthenticationMiddleware is absent from the app; the request path (outside /api/ and /ws/) skipped auth so state.user was never set; calling the endpoint with credentials stripped by a proxy so middleware authenticated nothing.","commonSituations":"Mounting routers under non-/api prefixes (e.g. /v2/thing) where _requires_auth returns False, so even a valid Bearer header path returns no user; TestClient tests bypassing middleware; misordered middleware stack.","solutions":["Ensure the route path starts with /api/ or /ws/ so the middleware authenticates, or extend _requires_auth","Add AuthenticationMiddleware to the app before routes that depend on request.state.user","Send a valid Bearer token so the middleware populates request.state.user"],"exampleFix":"# before\n@app.get('/v2/things')\nasync def things(user=Depends(require_authentication)): ...\n# path outside /api/* -> middleware never authenticates -> 401\n# after\n@app.get('/api/v2/things')\nasync def things(user=Depends(require_authentication)): ...","handlingStrategy":"validation","validationCode":"def dependency_will_pass(request) -> bool:\n    \"\"\"require_authentication reads request.state.user set by the middleware.\"\"\"\n    return getattr(request.state, \"user\", None) is not None","typeGuard":"def is_authenticated_request(request) -> bool:\n    state = getattr(request, \"state\", None)\n    user = getattr(state, \"user\", None) if state else None\n    return isinstance(user, dict) and \"username\" in user","tryCatchPattern":"from fastapi import HTTPException\n\ntry:\n    user = require_authentication(request)\nexcept HTTPException as e:\n    if e.status_code == 401:\n        # not bad credentials: middleware never ran for this path\n        return PlainTextResponse(\"Authentication required\", status_code=401,\n                                 headers={\"WWW-Authenticate\": \"Bearer\"})\n    raise","preventionTips":["Keep authenticated routes under /api/ or /ws/","Add the auth middleware before mounting dependent routers","In tests, use the full app (middleware included), not bare functions"],"tags":["auth","fastapi","dependencies","http-401"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}