wavetermdev/waveterm · error
error getting rpc response handler from context
Error message
error getting rpc response handler from context
What it means
GetConnNameFromContext extracts the connection name from the wshutil.RpcResponseHandler stored in ctx. This error is thrown when the context contains no RPC response handler, meaning the function was called outside of an active wsh RPC request and the connection name cannot be recovered. It is the direct source of the 'error getting connection name from context' wrapper in ParseURIAndReplaceCurrentHost.
Source
Thrown at pkg/remote/connparse/connparse.go:88
if conn.Host == ConnHostCurrent {
source, err := GetConnNameFromContext(ctx)
if err != nil {
return nil, fmt.Errorf("error getting connection name from context: %v", err)
}
// RPC context connection is empty for local connections
if source == "" {
source = wshrpc.LocalConnName
}
conn.Host = source
}
return conn, nil
}
func GetConnNameFromContext(ctx context.Context) (string, error) {
handler := wshutil.GetRpcResponseHandlerFromContext(ctx)
if handler == nil {
return "", fmt.Errorf("error getting rpc response handler from context")
}
return handler.GetRpcContext().Conn, nil
}
// ParseURI parses a connection URI and returns the connection type, host/path, and parameters.
func ParseURI(uri string) (*Connection, error) {
isWshShorthand := strings.HasPrefix(uri, "//")
split := strings.SplitN(uri, "://", 2)
var scheme string
var rest string
if isWshShorthand {
rest = strings.TrimPrefix(uri, "//")
} else if len(split) > 1 {
scheme = split[0]
rest = strings.TrimPrefix(split[1], "//")
} else {
rest = split[0]
}View on GitHub (pinned to a4447c1563)
Solutions
- Ensure the code path originates from an RPC request whose context was enriched via wshutil's context-with-handler middleware.
- Attach a wshutil.RpcResponseHandler to the context before calling (wshutil package provides the With-style constructor used by the RPC server).
- If running outside RPC, resolve the connection name by other means (config/default connection) and avoid the 'current' host placeholder.
- In tests, set up a stub handler whose GetRpcContext().Conn returns the expected connection name.
Example fix
// before
name, err := connparse.GetConnNameFromContext(ctx)
// after
if wshutil.GetRpcResponseHandlerFromContext(ctx) == nil {
ctx = wshutil.ContextWithRpcResponseHandler(ctx, handler)
}
name, err := connparse.GetConnNameFromContext(ctx) Defensive patterns
Strategy: try-catch
Validate before calling
if wshutil.GetRpcResponseHandlerFromContext(ctx) == nil {
return "", fmt.Errorf("context has no rpc response handler")
} Try / catch
name, err := connparse.GetConnNameFromContext(ctx)
if err != nil {
// fall back to a default/local connection
name = wshrpc.LocalConnName
} Prevention
- Propagate the original RPC request ctx into goroutines instead of context.Background().
- Use wshutil's context middleware consistently in all RPC entry points.
- Add a debug assertion logging when the handler is absent during development.
- Document that functions resolving 'current' require an RPC context.
When it happens
Trigger: Calling GetConnNameFromContext (directly or via ParseURIAndReplaceCurrentHost when conn.Host == ConnHostCurrent) with a context created without wshutil's context middleware, so wshutil.GetRpcResponseHandlerFromContext(ctx) returns nil.
Common situations: Background goroutines that drop the original request context; CLI tools or scripts calling remote copy/move helpers outside the RPC server; tests using context.TODO(); handlers spawned with a detached context.
Related errors
- error getting connection name from context: %v
- nil wshrpc passed to wshclient
- no default route
- response channel closed
- <resp.Error>
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/98e86c38cd5c3a16.
Report an issue: GitHub.