slimtoolkit/slim · error
invalid ws proto - %s
Error message
invalid ws proto - %s
What it means
NewWebsocketClient validates the websocket protocol string before constructing the client address. Only "ws" (and "wss", per IsValidWSProto) are accepted; anything else — http, https, empty-but-invalid overrides — makes construction fail with this error. This is a fail-fast guard against forming an unusable URL scheme.
Source
Thrown at pkg/app/master/probe/http/wsclient.go:41
PongCount acounter.Type
PingCount acounter.Type
Addr string
pongCh chan string
doneCh chan struct{}
}
type WebsocketMessage struct {
Type int
Data []byte
}
func NewWebsocketClient(proto, host, port string) (*WebsocketClient, error) {
if proto == "" {
proto = ProtoWS
}
if !IsValidWSProto(proto) {
return nil, fmt.Errorf("invalid ws proto - %s", proto)
}
wsclient := &WebsocketClient{
Addr: fmt.Sprintf("%s://%s:%s", proto, host, port),
doneCh: make(chan struct{}),
pongCh: make(chan string, 10),
}
return wsclient, nil
}
func IsValidWSProto(proto string) bool {
switch proto {
case ProtoWS, ProtoWSS:
return true
default:
return false
}View on GitHub (pinned to 81940d17fa)
Solutions
- Pass "ws" or "wss" as proto (correct case, scheme only, no trailing ://).
- Convert a full URL: extract the scheme and map https->wss, http->ws.
- Leave proto empty to get the default (ws) instead of passing an invalid scheme.
- Normalize case before calling: strings.ToLower(proto).
Example fix
// before
c, err := NewWebsocketClient("https", host, port)
// after
proto := "wss"
if r.URL.Scheme == "http" { proto = "ws" }
c, err := NewWebsocketClient(proto, host, port) Defensive patterns
Strategy: validation
Validate before calling
func validWSProto(p string) bool { return p == "" || p == "ws" || p == "wss" }
if !validWSProto(cfg.WSProto) {
log.Fatalf("ws proto must be ws or wss, got %q", cfg.WSProto)
} Type guard
func IsValidWSProto(proto string) bool {
return proto == "ws" || proto == "wss"
} Try / catch
c, err := NewWebsocketClient(proto, host, port)
if err != nil && strings.Contains(err.Error(), "invalid ws proto") {
return fmt.Errorf("configure scheme as ws or wss (map http->ws, https->wss): %w", err)
} Prevention
- Store only scheme values (ws/wss) in config, never full URLs.
- Map http->ws and https->wss when deriving from an HTTP URL.
- Rely on the empty-string default (ws) unless TLS is required (wss).
When it happens
Trigger: Calling NewWebsocketClient with a proto value that fails IsValidWSProto, e.g. passing "http", "https", "HTTP" (case sensitivity), or a full URL instead of a scheme.
Common situations: Configuring the HTTP probe's websocket endpoint from an environment/config value that stores a base URL (https://host) instead of a scheme-only value; copy-pasting from browser devtools; assuming http/https work for websockets.
Related errors
- podPort cannot be empty
- fcgi: invalid header version
- file path is not absolute
- file is not a binary
- bad parameter
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/1a6ab67b7beaa267.
Report an issue: GitHub.