{"record":{"id":"cbf4f22112f8e3c3","repo":"hashicorp/nomad","slug":"wserr-text","errorCode":null,"errorMessage":"wsErr.Text","messagePattern":"wsErr\\.Text","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/allocations_exec.go","lineNumber":66,"sourceCode":"\tconn, err := s.startConnection()\n\tif err != nil {\n\t\treturn -2, err\n\t}\n\tdefer conn.Close()\n\n\tsendErrCh := s.startTransmit(ctx, conn)\n\texitCh, recvErrCh := s.startReceiving(ctx, conn)\n\n\tfor {\n\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\treturn -2, ctx.Err()\n\t\tcase exitCode := <-exitCh:\n\t\t\treturn exitCode, nil\n\t\tcase recvErr := <-recvErrCh:\n\t\t\t// drop websocket code, not relevant to user\n\t\t\tif wsErr, ok := recvErr.(*websocket.CloseError); ok && wsErr.Text != \"\" {\n\t\t\t\treturn -2, errors.New(wsErr.Text)\n\t\t\t}\n\n\t\t\treturn -2, recvErr\n\t\tcase sendErr := <-sendErrCh:\n\t\t\treturn -2, fmt.Errorf(\"failed to send input: %w\", sendErr)\n\t\t}\n\t}\n}\n\nfunc (s *execSession) startConnection() (*websocket.Conn, error) {\n\t// First, attempt to connect to the node directly, but may fail due to network isolation\n\t// and network errors.  Fallback to using server-side forwarding instead.\n\tnodeClient, err := s.client.GetNodeClientWithTimeout(s.alloc.NodeID, ClientConnTimeout, s.q)\n\tif err == NodeDownErr {\n\t\treturn nil, NodeDownErr\n\t}\n\n\tq := s.q","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/api/allocations_exec.go#L48-L84","documentation":"When receiving from the exec websocket, a *websocket.CloseError with a non-empty Text is converted to a plain error carrying the server-supplied close reason; it fires when the Nomad server (or intermediate proxy) closes the exec stream and includes a human-readable explanation in the close frame.","triggerScenarios":"Thrown at api/allocations_exec.go:66 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the returned text for the server's close reason (e.g. auth failure, task exit, connection lost)","Re-establish the exec session and retry the command","Check Nomad agent and network/proxy health between client and server"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}