{"record":{"id":"5ea139d854f69bb4","repo":"louislam/dockge","slug":"terminal-not-found-or-it-is-not-a-interactive-term","errorCode":null,"errorMessage":"Terminal not found or it is not a Interactive Terminal.","messagePattern":"Terminal not found or it is not a Interactive Terminal\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"backend/agent-socket-handlers/terminal-socket-handler.ts","lineNumber":29,"sourceCode":"\n        agentSocket.on(\"terminalInput\", async (terminalName : unknown, cmd : unknown, callback) => {\n            try {\n                checkLogin(socket);\n\n                if (typeof(terminalName) !== \"string\") {\n                    throw new Error(\"Terminal name must be a string.\");\n                }\n\n                if (typeof(cmd) !== \"string\") {\n                    throw new Error(\"Command must be a string.\");\n                }\n\n                let terminal = Terminal.getTerminal(terminalName);\n                if (terminal instanceof InteractiveTerminal) {\n                    //log.debug(\"terminalInput\", \"Terminal found, writing to terminal.\");\n                    terminal.write(cmd);\n                } else {\n                    throw new Error(\"Terminal not found or it is not a Interactive Terminal.\");\n                }\n            } catch (e) {\n                callbackError(e, callback);\n            }\n        });\n\n        // Main Terminal\n        agentSocket.on(\"mainTerminal\", async (terminalName : unknown, callback) => {\n            try {\n                checkLogin(socket);\n\n                // Throw an error if console is not enabled\n                if (!server.config.enableConsole) {\n                    throw new ValidationError(\"Console is not enabled.\");\n                }\n\n                // TODO: Reset the name here, force one main terminal for now\n                terminalName = \"console\";","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/louislam/dockge/blob/f809ae192b571944ad773e9866d3e67064ae8043/backend/agent-socket-handlers/terminal-socket-handler.ts#L11-L47","documentation":"Thrown in the terminalInput handler when Terminal.getTerminal(terminalName) returns null or an object that is not an InteractiveTerminal. It means no interactive terminal is registered under the given name on the server, so the handler cannot write the command. This guards the terminal.write(cmd) call against an invalid target.","triggerScenarios":"Emitting 'terminalInput' with a terminalName that was never created, that was already removed/ended, or that refers to a non-interactive (e.g. main console) terminal.","commonSituations":"Client emits input after server restart (terminal registry lost), name mismatch between client and server (e.g. 'console' vs generated names), or writing to the main terminal via terminalInput instead of mainTerminal.","solutions":["Verify the terminal name matches one previously created via 'interactiveTerminal' or 'mainTerminal' on this connection.","Re-create the terminal (e.g. re-emit 'interactiveTerminal') after any server restart or disconnect before sending input.","Use the 'mainTerminal' event for the console terminal instead of 'terminalInput'.","Add a client-side existence check/log of the terminal name being used."],"exampleFix":"// before\nsocket.emit(\"terminalInput\", \"console\", \"ls\");\n// after\nconst name = \"main-console\"; // name used when creating the interactive terminal\nsocket.emit(\"terminalInput\", name, \"ls\"); // or use socket.emit(\"mainTerminal\", ...) for the console","handlingStrategy":"validation","validationCode":"function assertTerminalExists(name, knownTerminals) { if (!knownTerminals.includes(name)) throw new Error(`Terminal \"${name}\" not created yet`); }\nassertTerminalExists(terminalName, createdTerminals); socket.emit(\"terminalInput\", terminalName, cmd);","typeGuard":"const hasTerminal = (name) => typeof name === \"string\" && createdTerminals.includes(name);","tryCatchPattern":"socket.emit(\"terminalInput\", name, cmd, (res) => { if (res?.error) { recreateTerminal(name).then(() => retryInput(cmd)); } });","preventionTips":["Track which terminals the client created and only write to those.","Recreate terminals after reconnect/server restart before sending input.","Use 'mainTerminal' for the console, 'terminalInput' only for interactive terminals.","Keep terminal names in a single shared constant/store to avoid mismatches."],"tags":["validation","socket-io","terminal","state"],"backgroundTag":"terminal-not-found","analyzedSha":"f809ae192b571944ad773e9866d3e67064ae8043","analyzedAt":"2026-08-31T19:13:50.919Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}