louislam/dockge · error · Error

Invalid stackName or serviceName

Error message

Invalid stackName or serviceName

What it means

Thrown by the 'restartService' handler as a plain Error (not ValidationError, unlike its siblings) when stackName or serviceName is not a string. Same purpose: the handler accepts `unknown` socket payloads and rejects wrong types before touching Docker.

Source

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

                const stack = await Stack.getStack(server, stackName);
                await stack.stopService(socket, serviceName);
                callbackResult({
                    ok: true,
                    msg: "Service " + serviceName + " stopped"
                }, callback);
                server.sendStackList();
            } catch (e) {
                callbackError(e, callback);
            }
        });

        agentSocket.on("restartService", async (stackName: unknown, serviceName: unknown, callback) => {
            try {
                checkLogin(socket);

                if (typeof stackName !== "string" || typeof serviceName !== "string") {
                    throw new Error("Invalid stackName or serviceName");
                }

                const stack = await Stack.getStack(server, stackName, true);
                await stack.restartService(socket, serviceName);
                callbackResult({
                    ok: true,
                    msg: "Service " + serviceName + " restarted"
                }, callback);
            } catch (e) {
                callbackError(e, callback);
            }
        });

        // getExternalNetworkList
        agentSocket.on("getDockerNetworkList", async (callback) => {
            try {
                checkLogin(socket);
                const dockerNetworkList = await server.getDockerNetworkList();

View on GitHub (pinned to f809ae192b)

Solutions

  1. Pass stackName and serviceName as strings, in that order
  2. Guard before emit with typeof checks on both values
  3. Resolve ids/objects to their string names before calling
  4. Keep payload shapes consistent with startService/stopService to avoid drift

Example fix

// before
socket.emit("restartService", stack.id, service, cb);
// after
socket.emit("restartService", stack.name, service.name, cb);
Defensive patterns

Strategy: type-guard

Validate before calling

function validateRestartArgs(stackName: unknown, serviceName: unknown): boolean {
  return typeof stackName === "string" && typeof serviceName === "string";
}
if (!validateRestartArgs(stackName, serviceName)) throw new TypeError("restartService payload invalid");

Type guard

const isRestartPayload = (s: unknown, n: unknown): s is string => typeof s === "string" && typeof n === "string";

Try / catch

socket.emit("restartService", stackName, serviceName, (res) => {
  if (!res.ok) console.error("restartService rejected:", res.msg);
});

Prevention

When it happens

Trigger: socket.emit('restartService', stackName, serviceName) with a non-string in either slot — undefined service name, null stack reference, numeric id, or object passed by mistake.

Common situations: Restart action triggered from a stale UI row after the stack list refreshed; automation calling the socket API with ids; copy-paste of handler arguments in the wrong order.

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/308b54f0d00742dd. Report an issue: GitHub.