wavetermdev/waveterm · error

Invalid command type: ${commandType}

Error message

Invalid command type: ${commandType}

What it means

applyCommand only supports the command types "set", "del", and "append". Any other value falls through to the default branch and throws this error, since there is no handler for the requested mutation.

Source

Thrown at frontend/util/ijson.ts:248

    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. Print command.type and compare against the supported set: "set", "del", "append".
  2. Fix the typo or use a supported command type.
  3. Align versions: ensure the code generating commands and the code applying them agree on the command vocabulary.
  4. Add an exhaustive union type (e.g. IJsonCommand = SetCmd|DelCmd|AppendCmd) so TS rejects unknown types at compile time.

Example fix

// before
applyCommand(data, { type: "remove", path: "a.b" });
// after
applyCommand(data, { type: "del", path: "a.b" });
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED = new Set(["set", "del", "append"]);
if (!SUPPORTED.has(cmd?.type)) throw new Error(`unsupported ijson command type: ${cmd?.type}`);
applyCommand(data, cmd);

Type guard

type IJsonCommandType = "set" | "del" | "append";
function isIJsonCommandType(t: unknown): t is IJsonCommandType {
  return t === "set" || t === "del" || t === "append";
}

Try / catch

try {
  applyCommand(data, cmd);
} catch (e) {
  if (String(e.message).startsWith("Invalid command type")) {
    console.error("unknown command type, dropping:", cmd.type);
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing a command with type set to anything other than set/del/append — e.g. a typo ({type:'remove'}), a type from a newer/older protocol version, or a type field that is undefined/null and got stringified oddly before the earlier null check.

Common situations: Protocol drift between producer and consumer of commands (one side added 'insert', the other not upgraded), typos in hand-written command literals, or JSON round-trips that altered/renamed the type field.

Related errors


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