{"record":{"id":"eb57229a7b7049e1","repo":"wavetermdev/waveterm","slug":"error-getting-environment-with-pty-w","errorCode":null,"errorMessage":"error getting environment with PTY: %w","messagePattern":"error getting environment with PTY: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/remote/conncontroller/conncontroller.go","lineNumber":346,"sourceCode":"\t}\n\treturn true, clientVersion, \"\", nil\n}\n\n// for testing only -- trying to determine the env difference when attaching or not attaching a pty to an ssh session\nfunc (conn *SSHConn) GetEnvironmentMaps(ctx context.Context) (map[string]string, map[string]string, error) {\n\tclient := conn.GetClient()\n\tif client == nil {\n\t\treturn nil, nil, fmt.Errorf(\"ssh client is not connected\")\n\t}\n\n\tnoPtyEnv, err := conn.getEnvironmentNoPty(ctx, client)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"error getting environment without PTY: %w\", err)\n\t}\n\n\tptyEnv, err := conn.getEnvironmentWithPty(ctx, client)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"error getting environment with PTY: %w\", err)\n\t}\n\n\treturn noPtyEnv, ptyEnv, nil\n}\n\nfunc runSessionWithContext(ctx context.Context, session *ssh.Session, cmd string) error {\n\terrCh := make(chan error, 1)\n\n\tgo func() {\n\t\terrCh <- session.Run(cmd)\n\t}()\n\n\tselect {\n\tcase <-ctx.Done():\n\t\tsession.Close()\n\t\treturn ctx.Err()\n\tcase err := <-errCh:\n\t\treturn err","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/remote/conncontroller/conncontroller.go#L328-L364","documentation":"The second probe of GetEnvironmentMaps runs the same environment capture WITH a PTY allocated. Failures in that PTY session (command error, PTY request denied, connection drop) are wrapped as 'error getting environment with PTY'.","triggerScenarios":"conn.getEnvironmentWithPty returns an error — PTY allocation is refused by sshd, the shell fails under PTY, or the session errors before the env dump completes.","commonSituations":"sshd configured with PermitTTY no or limited ptys; shell profile that errors only in interactive/PTY mode; connection instability during interactive session setup; pty allocation limits hit (out of ptys).","solutions":["Check sshd_config on the remote allows PTY allocation (PermitTTY yes) and ptys are available","Inspect the wrapped inner error for the session/PTY failure detail","Reproduce with ssh -t host 'env' to see the PTY-mode failure directly","Fix interactive shell startup files that fail under PTY"],"exampleFix":"// server (sshd_config)\n// before\nPermitTTY no\n// after\nPermitTTY yes","handlingStrategy":"try-catch","validationCode":"// pty availability precheck\nout, err := client.CombinedOutput(\"ssh -T host true\") // or test RequestPty\nif err != nil {\n    return fmt.Errorf(\"pty allocation may be unavailable: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"noPty, pty, err := conn.GetEnvironmentMaps(ctx)\nif err != nil && strings.Contains(err.Error(), \"environment with PTY\") {\n    log.Printf(\"env probe (pty) failed: %v\", err) // fall back to noPty env\n}","preventionTips":["Ensure sshd allows PTY allocation (PermitTTY yes) on remotes","Keep interactive shell startup scripts error-free","Fall back to the no-PTY environment when the PTY probe fails"],"tags":["ssh","environment","pty"],"backgroundTag":"ssh-pty-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}