{"record":{"id":"a2dc7dd108ccd9e2","repo":"wavetermdev/waveterm","slug":"invalid-command-path-formatpath-path","errorCode":null,"errorMessage":"Invalid command path: ${formatPath(path)}","messagePattern":"Invalid command path: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/util/ijson.ts","lineNumber":235,"sourceCode":"        return [];\n    }\n    return command[\"path\"];\n}\n\nfunction applyCommand(data: any, command: any): any {\n    if (command == null) {\n        throw new Error(\"Invalid command (null)\");\n    }\n    if (!isObject(command)) {\n        throw new Error(\"Invalid command (not an object): \" + command);\n    }\n    const commandType = command.type;\n    if (commandType == null) {\n        throw new Error(\"Invalid command (no type): \" + command);\n    }\n    const path = getCommandPath(command);\n    if (!checkPath(path)) {\n        throw new Error(\"Invalid command path: \" + formatPath(path));\n    }\n    switch (commandType) {\n        case \"set\":\n            return setPath(data, path, command.value, null);\n\n        case \"del\":\n            return setPath(data, path, null, { remove: true });\n\n        case \"append\":\n            return setPath(data, path, command.value, { combinefn: combineFn_arrayAppend });\n\n        default:\n            throw new Error(\"Invalid command type: \" + commandType);\n    }\n}\n\nexport { applyCommand, combineFn_arrayAppend, getPath, setPath };\nexport type { PathType, SetPathOpts };","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/frontend/util/ijson.ts#L217-L253","documentation":"applyCommand applies an ijson mutation command (set/del/append) to a JSON object tree. Every command must carry a valid dot-separated path into the tree; if getCommandPath returns a path that fails checkPath (empty or malformed segments), this error is thrown rather than silently corrupting data.","triggerScenarios":"Calling applyCommand with a command whose path is empty, an empty string, an array containing empty/null segments, or a path built from undefined fields (e.g. {type:'set', path:'', value:x} or {type:'del', path:['a','']}).","commonSituations":"Building command paths programmatically from optional fields (a variable that is undefined), joining path segments with a template string that yields empty pieces, or deserializing commands from user/IPC input where the path field was dropped.","solutions":["Log formatPath(path) (the message already embeds it) and inspect which segment is empty or invalid.","Ensure the command object always has a non-empty path: default it or throw at construction time.","Validate paths with checkPath yourself before creating/queueing commands.","If the path is optional, guard the caller: only call applyCommand when the target field exists."],"exampleFix":"// before\nconst cmd = { type: \"set\", path: obj.prefix + \".name\", value: name };\napplyCommand(data, cmd);\n// after\nconst path = obj.prefix ? obj.prefix + \".name\" : \"name\";\nif (!path) throw new Error(\"cannot build command path\");\napplyCommand(data, { type: \"set\", path, value: name });","handlingStrategy":"validation","validationCode":"function isValidCommand(cmd) {\n  return cmd && cmd.type != null && checkPath(getCommandPath(cmd));\n}\nif (!isValidCommand(cmd)) throw new Error(\"skipping invalid ijson command: \" + JSON.stringify(cmd));\napplyCommand(data, cmd);","typeGuard":"function isIJsonCommand(cmd) {\n  return (\n    typeof cmd === \"object\" && cmd !== null &&\n    [\"set\", \"del\", \"append\"].includes(cmd.type) &&\n    typeof cmd.path === \"string\" && cmd.path.length > 0\n  );\n}","tryCatchPattern":"try {\n  applyCommand(data, cmd);\n} catch (e) {\n  if (String(e.message).startsWith(\"Invalid command path\")) {\n    console.error(\"bad command path:\", JSON.stringify(cmd));\n    return; // skip or queue for repair\n  }\n  throw e;\n}","preventionTips":["Never build paths by naive string concatenation of possibly-undefined values.","Run checkPath on every path at command-construction time, not just at apply time.","Type commands with a discriminated union so missing/empty path fields fail compilation.","Log formatPath(path) in error handlers to speed diagnosis."],"tags":["ijson","path-validation","invalid-argument"],"backgroundTag":"invalid-path","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}