{"record":{"id":"19dccd9e9a8e50db","repo":"ruvnet/ruflo","slug":"invalid-completion-type","errorCode":null,"errorMessage":"Invalid completion type","messagePattern":"Invalid completion type","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ruflo/src/ruvocal/src/lib/server/endpoints/openai/endpointOai.ts","lineNumber":264,"sourceCode":"\t\t\t\t\t{\n\t\t\t\t\t\tbody: { ...body, ...extraBody },\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\"ChatUI-Conversation-ID\": conversationId?.toString() ?? \"\",\n\t\t\t\t\t\t\t\"X-use-cache\": \"false\",\n\t\t\t\t\t\t\t...(locals?.token ? { Authorization: `Bearer ${locals.token}` } : {}),\n\t\t\t\t\t\t\t// Bill to organization if configured\n\t\t\t\t\t\t\t...(locals?.billingOrganization\n\t\t\t\t\t\t\t\t? { \"X-HF-Bill-To\": locals.billingOrganization }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsignal: abortSignal,\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\treturn openAIChatToTextGenerationSingle(openChatAICompletion, () => routerMetadata);\n\t\t\t}\n\t\t};\n\t} else {\n\t\tthrow new Error(\"Invalid completion type\");\n\t}\n}\n","sourceCodeStart":246,"sourceCodeEnd":267,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/ruflo/src/ruvocal/src/lib/server/endpoints/openai/endpointOai.ts#L246-L267","documentation":"Thrown in the final else branch of endpointOai when the parsed completion value is neither 'completions' nor 'chat_completions'. In practice this is effectively unreachable: endpointOAIParametersSchema.parse() validates completion against z.union([literal('completions'), literal('chat_completions')]) with a default of 'chat_completions', so any value reaching the branch must have bypassed Zod (e.g. calling the internal function with hand-parsed input, or a schema regression that widened the union).","triggerScenarios":"Calling endpointOai with a completion value other than the two literals after skipping endpointOAIParametersSchema.parse — e.g. an internal caller destructures input directly, or a future schema change adds a literal without adding a matching branch. Through normal Zod-validated entry the throw cannot fire.","commonSituations":"A refactor added a third completion mode to the schema union but forgot to add its branch in the function; a caller bypasses .parse() and passes a raw object; a default was removed so undefined reaches the branch (only possible if the schema's default is also removed).","solutions":["Always feed input through endpointOAIParametersSchema.parse(input) so completion is validated/defaulted to a known literal.","If you add a new completion mode, add its branch (e.g. else if (completion === 'responses')) before the final else.","Search for direct callers of endpointOai that skip the schema and route them through it.","Turn the final else into an exhaustiveness check on a string-enum union so a new literal is a compile error."],"exampleFix":"// before\n} else {\n  throw new Error(\"Invalid completion type\");\n}\n\n// after — exhaustiveness via never\ntype Completion = \"completions\" | \"chat_completions\";\nfunction assertNever(x: never): never { throw new Error(`Invalid completion type: ${x}`); }\n} else {\n  assertNever(completion as never);\n}","handlingStrategy":"type-guard","validationCode":"const COMPLETIONS = ['completions', 'chat_completions'] as const;\ntype Completion = typeof COMPLETIONS[number];\nfunction parseCompletion(v: unknown): Completion {\n  if (typeof v === 'string' && (COMPLETIONS as readonly string[]).includes(v)) return v as Completion;\n  return 'chat_completions'; // safe default\n}","typeGuard":"function isValidCompletion(v: unknown): v is 'completions' | 'chat_completions' { return v === 'completions' || v === 'chat_completions'; }","tryCatchPattern":null,"preventionTips":["Always route input through endpointOAIParametersSchema.parse.","Convert the final else into an exhaustiveness check (assertNever) so a new literal is a compile error.","Add a branch whenever you widen the schema union."],"tags":["validation","typescript","defensive","ruvocal"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}