louislam/dockge · error · Error
URL must be a string
Error message
URL must be a string
What it means
The 'removeAgent' socket event requires the agent's URL as a string, which is used as the instance identifier by instanceManager.remove(url). Since the argument is unknown, a typeof check throws this Error for any non-string value before attempting removal.
Source
Thrown at backend/socket-handlers/manage-agent-socket-handler.ts:51
callbackResult({
ok: true,
msg: "agentAddedSuccessfully",
msgi18n: true,
}, callback);
} catch (e) {
callbackError(e, callback);
}
});
// removeAgent
socket.on("removeAgent", async (url : unknown, callback : unknown) => {
try {
log.debug("manage-agent-socket-handler", "removeAgent");
checkLogin(socket);
if (typeof(url) !== "string") {
throw new Error("URL must be a string");
}
let manager = socket.instanceManager;
await manager.remove(url);
server.disconnectAllSocketClients(undefined, socket.id);
manager.sendAgentList();
callbackResult({
ok: true,
msg: "agentRemovedSuccessfully",
msgi18n: true,
}, callback);
} catch (e) {
callbackError(e, callback);
}
});
View on GitHub (pinned to f809ae192b)
Solutions
- Pass the agent URL string exactly as it was added, e.g. 'http://agent:5001'.
- Extract from the object first: socket.emit('removeAgent', agent.url, cb).
- Guard with typeof url === 'string' before emitting.
Example fix
// before
socket.emit('removeAgent', agent, cb); // agent is an object
// after
socket.emit('removeAgent', agent.url, cb); Defensive patterns
Strategy: type-guard
Validate before calling
function isAgentUrl(v) {
return typeof v === 'string' && v.length > 0 && /^https?:\/\//.test(v);
} Type guard
function isString(v) { return typeof v === 'string'; } Try / catch
if (typeof url !== 'string') {
throw new Error('URL must be a string');
}
socket.emit('removeAgent', url, cb); Prevention
- Pass agent.url, never the whole agent object
- Ensure agent records always carry a url before offering removal
- Use the exact URL string the agent was added with
When it happens
Trigger: Emitting 'removeAgent' with undefined, null, a number, or an object (e.g. { url: ... }) instead of the URL string itself.
Common situations: Passing the whole agent object rather than its url property; undefined when the agent record lacks a url; automation scripts removing agents positionally with wrong args.
Understand the failure class
Background: "Wrong argument type", "must be a string", "expected Array or Prism::Scope": TypeError and ArgumentError when a library receives a value of the wrong type — this error's family across 28 libraries.
Related errors
- Data must be an object
- dockerRunCommand must be a string
- Name must be a string
- Stack name must be a string
- Stack name and service name must be strings
AI-assisted analysis of louislam/dockge@f809ae192b (2026-08-31).
Data as JSON: /api/errors/8f3ca9f77024e17b.
Report an issue: GitHub.