{"record":{"id":"5e342b083177e81e","repo":"ruvnet/ruflo","slug":"vector-must-be-a-json-array-of-numbers-got-r","errorCode":null,"errorMessage":"--vector must be a JSON array of numbers, got: ${raw}","messagePattern":"--vector must be a JSON array of numbers, got: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/plugin-iot-cognitum/src/cli-commands.ts","lineNumber":17,"sourceCode":"import type { CLICommandDefinition, PluginContext } from '@claude-flow/shared/src/plugin-interface.js';\nimport type { IoTCoordinator } from './application/iot-coordinator.js';\nimport { getDeviceTrustLabel } from './domain/entities/device-trust-level.js';\n\ntype CoordinatorGetter = () => IoTCoordinator | null;\ntype ContextGetter = () => PluginContext | null;\n\nfunction requireCoordinator(get: CoordinatorGetter): IoTCoordinator {\n  const c = get();\n  if (!c) throw new Error('IoT Cognitum not initialized. Run \"iot register\" first.');\n  return c;\n}\n\nfunction parseVector(raw: string): number[] {\n  const parsed = JSON.parse(raw) as unknown;\n  if (!Array.isArray(parsed) || !parsed.every((n) => typeof n === 'number')) {\n    throw new Error(`--vector must be a JSON array of numbers, got: ${raw}`);\n  }\n  return parsed as number[];\n}\n\nexport function createCliCommands(\n  getCoordinator: CoordinatorGetter,\n  _getContext: ContextGetter,\n): CLICommandDefinition[] {\n  return [\n    {\n      name: 'iot init',\n      description: 'Initialize IoT Cognitum plugin configuration',\n      options: [\n        { name: 'fleet-id', description: 'Default fleet identifier', type: 'string', default: 'default' },\n        { name: 'zone-id', description: 'Default IEC 62443 security zone', type: 'string', default: 'zone-0' },\n        { name: 'insecure', description: 'Allow TLS-insecure connections', type: 'boolean', default: true },\n      ],\n      handler: async (args) => {","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/plugin-iot-cognitum/src/cli-commands.ts#L1-L35","documentation":"Validates the --vector CLI flag: the string must parse as JSON and the result must be an array whose every element is a number. Note the ordering — malformed JSON makes JSON.parse itself throw SyntaxError first; this specific message fires when the JSON is syntactically valid but not a flat number[] (an object, or an array containing strings, nulls, booleans, or nested arrays).","triggerScenarios":"Passing --vector '{\"values\":[1]}' (object, not array), '[1,\"2\"]', '[1,null]', '[[1,2]]', or any valid-JSON shape that is not a flat array of numbers.","commonSituations":"Shell quoting that mangles the JSON; hand-written vectors using strings or null placeholders for missing sensor values; attempting the metadata-object form that only the stdin channel accepts.","solutions":["Pass a flat JSON array of numbers, e.g. --vector '[0.1, 0.2, 0.3]'","Quote the argument in the shell so brackets and quotes survive intact","Replace strings, nulls, and nested arrays with plain numbers (null/NaN placeholders are not accepted)"],"exampleFix":"# before\n$ iot ingest --device-id seed-42 --vector '[0.1, null, \"0.3\"]'\n# Error: --vector must be a JSON array of numbers\n\n# after\n$ iot ingest --device-id seed-42 --vector '[0.1, 0.0, 0.3]'","handlingStrategy":"validation","validationCode":"const parsed: unknown = JSON.parse(raw);\nif (!isNumberArray(parsed)) {\n  throw new Error(`--vector must be a flat JSON array of numbers, got: ${raw}`);\n}\nspawnSync('iot', ['ingest', '--device-id', deviceId, '--vector', JSON.stringify(parsed)]);","typeGuard":"function isNumberArray(v: unknown): v is number[] {\n  return Array.isArray(v) && v.every((n) => typeof n === 'number' && Number.isFinite(n));\n}","tryCatchPattern":"try {\n  const vector = parseVectorCli(raw);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('--vector must be a JSON array')) {\n    // sanitize the data or re-prompt; do not re-submit the same string\n  } else throw e;\n}","preventionTips":["Build CLI arguments programmatically with JSON.stringify instead of string concatenation","Sanitize sensor data (drop nulls, coerce numeric strings) before building the vector","Single-quote JSON arguments in POSIX shells so quoting survives"],"tags":["cli","argument-validation","json","iot"],"backgroundTag":"invalid-argument-format","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}