louislam/dockge · info · ValidationError

Name must be a string

Error message

Name must be a string

What it means

The deleteStack agent socket handler validates that the first argument is a string before using it as a stack name; a non-string (number, object, undefined, null) throws ValidationError('Name must be a string'). This is an input validation guard against malformed socket events.

Source

Thrown at backend/agent-socket-handlers/docker-socket-handler.ts:47

            try {
                checkLogin(socket);
                await this.saveStack(server, name, composeYAML, composeENV, isAdd);
                callbackResult({
                    ok: true,
                    msg: "Saved",
                    msgi18n: true,
                }, callback);
                server.sendStackList();
            } catch (e) {
                callbackError(e, callback);
            }
        });

        agentSocket.on("deleteStack", async (name : unknown, callback) => {
            try {
                checkLogin(socket);
                if (typeof(name) !== "string") {
                    throw new ValidationError("Name must be a string");
                }
                const stack = await Stack.getStack(server, name);

                try {
                    await stack.delete(socket);
                } catch (e) {
                    server.sendStackList();
                    throw e;
                }

                server.sendStackList();
                callbackResult({
                    ok: true,
                    msg: "Deleted",
                    msgi18n: true,
                }, callback);

            } catch (e) {

View on GitHub (pinned to f809ae192b)

Solutions

  1. Emit deleteStack with a plain string stack name, e.g. agentSocket.emit('deleteStack', 'my-stack', callback)
  2. Check the caller is passing the name property, not an object containing it
  3. Handle the callbackError response (ok:false, msg:'Name must be a string') in the client and fix the payload

Example fix

// before
agentSocket.emit("deleteStack", { name: "my-stack" }, cb);
// after
agentSocket.emit("deleteStack", "my-stack", cb);
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof name !== "string" || name.length === 0) {
    throw new Error("deleteStack requires a non-empty string name");
}

Type guard

function isStackName(v: unknown): v is string {
    return typeof v === "string" && v.length > 0;
}

Try / catch

agentSocket.emit("deleteStack", name, (res) => {
    if (!res.ok && res.msg === "Name must be a string") {
        // fix payload: name must be a plain string
    }
});

Prevention

When it happens

Trigger: A client emits agent event 'deleteStack' with a non-string first argument — e.g. deleteStack(undefined), a parsed JSON object, a numeric id, or a forgotten argument so name is undefined.

Common situations: Custom scripts or API clients passing a stack id instead of the stack name; omitting the argument when calling the socket event; serialization bugs where the name arrives as an object.

Understand the failure class

Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.

Related errors


AI-assisted analysis of louislam/dockge@f809ae192b (2026-08-31). Data as JSON: /api/errors/b1b1f0ad389408e0. Report an issue: GitHub.