MCPcopy Index your code
hub / github.com/simstudioai/sim / formatSSHError

Function formatSSHError

apps/sim/app/api/tools/ssh/utils.ts:35–103  ·  view source on GitHub ↗

* Format SSH error with helpful troubleshooting context

(err: Error, config: { host: string; port: number })

Source from the content-addressed store, hash-verified

33 * Format SSH error with helpful troubleshooting context
34 */
35function formatSSHError(err: Error, config: { host: string; port: number }): Error {
36 const errorMessage = err.message.toLowerCase()
37 const host = config.host
38 const port = config.port
39
40 if (errorMessage.includes('econnrefused') || errorMessage.includes('connection refused')) {
41 return new Error(
42 `Connection refused to ${host}:${port}. ` +
43 `Please verify: (1) SSH server is running on the target machine, ` +
44 `(2) Port ${port} is correct (default SSH port is 22), ` +
45 `(3) Firewall allows connections to port ${port}.`
46 )
47 }
48
49 if (errorMessage.includes('econnreset') || errorMessage.includes('connection reset')) {
50 return new Error(
51 `Connection reset by ${host}:${port}. ` +
52 `This usually means: (1) Wrong port number (SSH default is 22), ` +
53 `(2) Server rejected the connection, ` +
54 `(3) Network/firewall interrupted the connection. ` +
55 `Verify your SSH server configuration and port number.`
56 )
57 }
58
59 if (errorMessage.includes('etimedout') || errorMessage.includes('timeout')) {
60 return new Error(
61 `Connection timed out to ${host}:${port}. ` +
62 `Please verify: (1) Host "${host}" is reachable, ` +
63 `(2) No firewall is blocking the connection, ` +
64 `(3) The SSH server is responding.`
65 )
66 }
67
68 if (errorMessage.includes('enotfound') || errorMessage.includes('getaddrinfo')) {
69 return new Error(
70 `Could not resolve hostname "${host}". ` +
71 `Please verify the hostname or IP address is correct.`
72 )
73 }
74
75 if (errorMessage.includes('authentication') || errorMessage.includes('auth')) {
76 return new Error(
77 `Authentication failed for user on ${host}:${port}. ` +
78 `Please verify: (1) Username is correct, ` +
79 `(2) Password or private key is valid, ` +
80 `(3) User has SSH access on the server.`
81 )
82 }
83
84 if (
85 errorMessage.includes('key') &&
86 (errorMessage.includes('parse') || errorMessage.includes('invalid'))
87 ) {
88 return new Error(
89 `Invalid private key format. ` +
90 `Please ensure you're using a valid OpenSSH private key. ` +
91 `The key should start with "-----BEGIN" and end with "-----END".`
92 )

Callers 1

createSSHConnectionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected