{"record":{"id":"d67feb1b40ead539","repo":"wavetermdev/waveterm","slug":"resp-error","errorCode":null,"errorMessage":"<resp.Error>","messagePattern":"<resp\\.Error>","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wshutil/wshrpc.go","lineNumber":605,"sourceCode":"\t\treturn false\n\tdefault:\n\t\treturn false\n\t}\n}\n\nfunc (handler *RpcRequestHandler) NextResponse() (any, error) {\n\tvar resp *RpcMessage\n\tif handler.cachedResp != nil {\n\t\tresp = handler.cachedResp\n\t\thandler.cachedResp = nil\n\t} else {\n\t\tresp = <-handler.respCh\n\t}\n\tif resp == nil {\n\t\treturn nil, errors.New(\"response channel closed\")\n\t}\n\tif resp.Error != \"\" {\n\t\treturn nil, errors.New(resp.Error)\n\t}\n\treturn resp.Data, nil\n}\n\nfunc (handler *RpcRequestHandler) finalize() {\n\thandler.callContextCancelFn()\n\tif handler.reqId != \"\" {\n\t\thandler.w.unregisterRpc(handler.reqId, nil)\n\t}\n}\n\nfunc (handler *RpcRequestHandler) callContextCancelFn() {\n\tcancelFnPtr := handler.ctxCancelFn.Swap(nil)\n\tif cancelFnPtr != nil && *cancelFnPtr != nil {\n\t\t(*cancelFnPtr)()\n\t}\n}\n","sourceCodeStart":587,"sourceCodeEnd":623,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wshutil/wshrpc.go#L587-L623","documentation":"WshRpc responses carry an Error string; when the remote handler returns an error, the client converts it with errors.New(resp.Error). So this message is arbitrary — it is the exact error text produced by the remote wsh command implementation, relayed to the caller.","triggerScenarios":"Any wsh RPC whose server-side handler returns an error: the client-side call (e.g. SendRpc/SendComplexRequest followed by Wait) returns errors.New(resp.Error) with the handler's error message verbatim.","commonSituations":"File operations failing on the remote (missing file, permission denied); blockcontroller commands on invalid block IDs; any application-level validation error raised inside the remote command handler.","solutions":["Read the error text — it names the actual remote failure; fix the root cause on the handler side.","Validate inputs (paths, IDs, options) before sending the RPC.","Check remote-side logs for the originating error in the command handler.","Handle per-command error semantics in your caller instead of treating it as a transport bug.","Ensure both client and server use compatible protocol versions to avoid handler mismatches."],"exampleFix":"// before\n_, err := wshclient.CommandRun(connCtx, req)\nif err != nil { return err } // opaque remote error\n// after\n_, err := wshclient.CommandRun(connCtx, req)\nif err != nil {\n    return fmt.Errorf(\"remote command failed: %w\", err) // err.Error() == the handler's message\n}","handlingStrategy":"try-catch","validationCode":"// validate inputs the remote handler checks (paths exist, IDs valid) before calling the RPC","typeGuard":null,"tryCatchPattern":"out, err := client.SendRpc(command, args, opts)\nif err != nil {\n    return fmt.Errorf(\"%s failed on remote: %w\", command, err) // err text == handler's message\n}","preventionTips":["Read the error string — it names the remote root cause.","Keep handler error messages actionable and prefixed with the command name.","Validate remote resources exist before invoking.","Keep client/server protocol versions in sync."],"tags":["go","rpc","remote-error"],"backgroundTag":"remote-rpc-handler-error","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}