{"record":{"id":"8f3ca9f77024e17b","repo":"louislam/dockge","slug":"url-must-be-a-string","errorCode":null,"errorMessage":"URL must be a string","messagePattern":"URL must be a string","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"backend/socket-handlers/manage-agent-socket-handler.ts","lineNumber":51,"sourceCode":"                callbackResult({\n                    ok: true,\n                    msg: \"agentAddedSuccessfully\",\n                    msgi18n: true,\n                }, callback);\n\n            } catch (e) {\n                callbackError(e, callback);\n            }\n        });\n\n        // removeAgent\n        socket.on(\"removeAgent\", async (url : unknown, callback : unknown) => {\n            try {\n                log.debug(\"manage-agent-socket-handler\", \"removeAgent\");\n                checkLogin(socket);\n\n                if (typeof(url) !== \"string\") {\n                    throw new Error(\"URL must be a string\");\n                }\n\n                let manager = socket.instanceManager;\n                await manager.remove(url);\n\n                server.disconnectAllSocketClients(undefined, socket.id);\n                manager.sendAgentList();\n\n                callbackResult({\n                    ok: true,\n                    msg: \"agentRemovedSuccessfully\",\n                    msgi18n: true,\n                }, callback);\n            } catch (e) {\n                callbackError(e, callback);\n            }\n        });\n","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/louislam/dockge/blob/f809ae192b571944ad773e9866d3e67064ae8043/backend/socket-handlers/manage-agent-socket-handler.ts#L33-L69","documentation":"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.","triggerScenarios":"Emitting 'removeAgent' with undefined, null, a number, or an object (e.g. { url: ... }) instead of the URL string itself.","commonSituations":"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.","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."],"exampleFix":"// before\nsocket.emit('removeAgent', agent, cb); // agent is an object\n// after\nsocket.emit('removeAgent', agent.url, cb);","handlingStrategy":"type-guard","validationCode":"function isAgentUrl(v) {\n    return typeof v === 'string' && v.length > 0 && /^https?:\\/\\//.test(v);\n}","typeGuard":"function isString(v) { return typeof v === 'string'; }","tryCatchPattern":"if (typeof url !== 'string') {\n    throw new Error('URL must be a string');\n}\nsocket.emit('removeAgent', url, cb);","preventionTips":["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"],"tags":["validation","input-validation","typescript","agents"],"backgroundTag":"wrong-argument-type","analyzedSha":"f809ae192b571944ad773e9866d3e67064ae8043","analyzedAt":"2026-08-31T19:13:50.919Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}