{"record":{"id":"1a6ab67b7beaa267","repo":"slimtoolkit/slim","slug":"invalid-ws-proto-s","errorCode":null,"errorMessage":"invalid ws proto - %s","messagePattern":"invalid ws proto - (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/master/probe/http/wsclient.go","lineNumber":41,"sourceCode":"\tPongCount acounter.Type\n\tPingCount acounter.Type\n\tAddr      string\n\tpongCh    chan string\n\tdoneCh    chan struct{}\n}\n\ntype WebsocketMessage struct {\n\tType int\n\tData []byte\n}\n\nfunc NewWebsocketClient(proto, host, port string) (*WebsocketClient, error) {\n\tif proto == \"\" {\n\t\tproto = ProtoWS\n\t}\n\n\tif !IsValidWSProto(proto) {\n\t\treturn nil, fmt.Errorf(\"invalid ws proto - %s\", proto)\n\t}\n\n\twsclient := &WebsocketClient{\n\t\tAddr:   fmt.Sprintf(\"%s://%s:%s\", proto, host, port),\n\t\tdoneCh: make(chan struct{}),\n\t\tpongCh: make(chan string, 10),\n\t}\n\n\treturn wsclient, nil\n}\n\nfunc IsValidWSProto(proto string) bool {\n\tswitch proto {\n\tcase ProtoWS, ProtoWSS:\n\t\treturn true\n\tdefault:\n\t\treturn false\n\t}","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/master/probe/http/wsclient.go#L23-L59","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nc, err := NewWebsocketClient(\"https\", host, port)\n// after\nproto := \"wss\"\nif r.URL.Scheme == \"http\" { proto = \"ws\" }\nc, err := NewWebsocketClient(proto, host, port)","handlingStrategy":"validation","validationCode":"func validWSProto(p string) bool { return p == \"\" || p == \"ws\" || p == \"wss\" }\nif !validWSProto(cfg.WSProto) {\n    log.Fatalf(\"ws proto must be ws or wss, got %q\", cfg.WSProto)\n}","typeGuard":"func IsValidWSProto(proto string) bool {\n    return proto == \"ws\" || proto == \"wss\"\n}","tryCatchPattern":"c, err := NewWebsocketClient(proto, host, port)\nif err != nil && strings.Contains(err.Error(), \"invalid ws proto\") {\n    return fmt.Errorf(\"configure scheme as ws or wss (map http->ws, https->wss): %w\", err)\n}","preventionTips":["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)."],"tags":["websocket","http-probe","validation"],"backgroundTag":"invalid-url-scheme","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}