{"record":{"id":"434117f2e145dddc","repo":"wavetermdev/waveterm","slug":"getting-variable-w","errorCode":null,"errorMessage":"getting variable: %w","messagePattern":"getting variable: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-getvar.go","lineNumber":94,"sourceCode":"\t\treturn getAllVariables(fullORef.OID)\n\t}\n\n\t// Single variable case - existing logic\n\tif len(args) != 1 {\n\t\tOutputHelpMessage(cmd)\n\t\treturn fmt.Errorf(\"requires a key argument\")\n\t}\n\n\tkey := args[0]\n\tcommandData := wshrpc.CommandVarData{\n\t\tKey:      key,\n\t\tZoneId:   fullORef.OID,\n\t\tFileName: getVarFileName,\n\t}\n\n\tresp, err := wshclient.GetVarCommand(RpcClient, commandData, &wshrpc.RpcOpts{Timeout: 2000})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting variable: %w\", err)\n\t}\n\n\tif !resp.Exists {\n\t\tWshExitCode = 1\n\t\treturn nil\n\t}\n\n\tWriteStdout(\"%s\", resp.Val)\n\tif shouldPrintNewline() {\n\t\tWriteStdout(\"\\n\")\n\t}\n\n\treturn nil\n}\n\nfunc getAllVariables(zoneId string) error {\n\tcommandData := wshrpc.CommandVarData{\n\t\tZoneId:   zoneId,","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-getvar.go#L76-L112","documentation":"This wraps any failure of the GetVarCommand RPC with a 2000ms timeout (cmd/wshcmd-getvar.go:94). The underlying error is usually an RPC transport problem — no connection to the Wave Terminal block/client, timed-out request, or server-side failure resolving the variable zone — not 'key not found' (a missing key returns Exists=false with exit code 1, not this error).","triggerScenarios":"Calling `wsh getvar KEY` when the wsh RPC client cannot reach the target (Wave app not running, block closed between resolve and call, connection to remote dropped, or the 2s timeout elapses).","commonSituations":"Running wsh from a remote/ssh session whose connection to the Wave client is down; targeting a block that just closed; slow/saturated connection exceeding the 2s RPC timeout.","solutions":["Verify the Wave app / target block is running and reachable, then retry `wsh getvar KEY`","Use `wsh getvar --local KEY` or a valid --block target to ensure the zone resolves correctly","Check the underlying wrapped error (rpc timeout vs connection refused) and address transport accordingly; increase timeout only if the server is slow"],"exampleFix":"// before\nwsh getvar FOO   # fails: connection down\n// after\nwsh conn show    # confirm connection state\nwsh getvar FOO   # retry once reachable","handlingStrategy":"try-catch","validationCode":"wsh conn show || { echo 'no connection to Wave app'; exit 1; }","typeGuard":null,"tryCatchPattern":"if ! out=$(wsh getvar FOO 2>err.txt); then\n  if grep -qi 'timeout\\|connection' err.txt; then\n    echo 'RPC transport failed; check the Wave app is running';\n  fi\n  exit 1\nfi","preventionTips":["Ensure the Wave app and target block are alive before reading vars","Keep ssh/remote connections stable; reconnect before scripting","Remember missing keys exit 1 (Exists=false) — only transport errors produce this message"],"tags":["rpc","network","wsh"],"backgroundTag":"rpc-request-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}