wavetermdev/waveterm · error

Invalid command path: ${formatPath(path)}

Error message

Invalid command path: ${formatPath(path)}

What it means

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.

Source

Thrown at frontend/util/ijson.ts:235

        return [];
    }
    return command["path"];
}

function applyCommand(data: any, command: any): any {
    if (command == null) {
        throw new Error("Invalid command (null)");
    }
    if (!isObject(command)) {
        throw new Error("Invalid command (not an object): " + command);
    }
    const commandType = command.type;
    if (commandType == null) {
        throw new Error("Invalid command (no type): " + command);
    }
    const path = getCommandPath(command);
    if (!checkPath(path)) {
        throw new Error("Invalid command path: " + formatPath(path));
    }
    switch (commandType) {
        case "set":
            return setPath(data, path, command.value, null);

        case "del":
            return setPath(data, path, null, { remove: true });

        case "append":
            return setPath(data, path, command.value, { combinefn: combineFn_arrayAppend });

        default:
            throw new Error("Invalid command type: " + commandType);
    }
}

export { applyCommand, combineFn_arrayAppend, getPath, setPath };
export type { PathType, SetPathOpts };

View on GitHub (pinned to a4447c1563)

Solutions

  1. Log formatPath(path) (the message already embeds it) and inspect which segment is empty or invalid.
  2. Ensure the command object always has a non-empty path: default it or throw at construction time.
  3. Validate paths with checkPath yourself before creating/queueing commands.
  4. If the path is optional, guard the caller: only call applyCommand when the target field exists.

Example fix

// before
const cmd = { type: "set", path: obj.prefix + ".name", value: name };
applyCommand(data, cmd);
// after
const path = obj.prefix ? obj.prefix + ".name" : "name";
if (!path) throw new Error("cannot build command path");
applyCommand(data, { type: "set", path, value: name });
Defensive patterns

Strategy: validation

Validate before calling

function isValidCommand(cmd) {
  return cmd && cmd.type != null && checkPath(getCommandPath(cmd));
}
if (!isValidCommand(cmd)) throw new Error("skipping invalid ijson command: " + JSON.stringify(cmd));
applyCommand(data, cmd);

Type guard

function isIJsonCommand(cmd) {
  return (
    typeof cmd === "object" && cmd !== null &&
    ["set", "del", "append"].includes(cmd.type) &&
    typeof cmd.path === "string" && cmd.path.length > 0
  );
}

Try / catch

try {
  applyCommand(data, cmd);
} catch (e) {
  if (String(e.message).startsWith("Invalid command path")) {
    console.error("bad command path:", JSON.stringify(cmd));
    return; // skip or queue for repair
  }
  throw e;
}

Prevention

When it happens

Trigger: 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','']}).

Common situations: 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.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/a2dc7dd108ccd9e2. Report an issue: GitHub.