yudai/gotty · error
failed to compile regular expression of Websocket Origin: %s
Error message
failed to compile regular expression of Websocket Origin: %s
What it means
New() validates the WSOrigin option by compiling it as a Go regular expression. If the pattern is syntactically invalid, regexp.Compile fails and the error is wrapped with the offending pattern so you can see exactly which string was rejected. The compiled matcher is later used to check the Origin header of WebSocket connections.
Source
Thrown at server/server.go:64
if err != nil {
return nil, errors.Wrapf(err, "failed to read custom index file at `%s`", path)
}
}
indexTemplate, err := template.New("index").Parse(string(indexData))
if err != nil {
panic("index template parse failed") // must be valid
}
titleTemplate, err := noesctmpl.New("title").Parse(options.TitleFormat)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse window title format `%s`", options.TitleFormat)
}
var originChekcer func(r *http.Request) bool
if options.WSOrigin != "" {
matcher, err := regexp.Compile(options.WSOrigin)
if err != nil {
return nil, errors.Wrapf(err, "failed to compile regular expression of Websocket Origin: %s", options.WSOrigin)
}
originChekcer = func(r *http.Request) bool {
return matcher.MatchString(r.Header.Get("Origin"))
}
}
return &Server{
factory: factory,
options: options,
upgrader: &websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
Subprotocols: webtty.Protocols,
CheckOrigin: originChekcer,
},
indexTemplate: indexTemplate,
titleTemplate: titleTemplate,View on GitHub (pinned to a080c85cbc)
Solutions
- Fix the WSOrigin regex syntax in your options/config (escape dots, use .* not *, balance parens)
- Test the pattern with Go regexp (or a regex tester with RE2 semantics) before launching
- If you meant a plain origin match, escape metacharacters: https://example\.com
Example fix
// before options.WSOrigin = "*.example.com" // after options.WSOrigin = ".*\.example\.com"
Defensive patterns
Strategy: validation
Validate before calling
if _, err := regexp.Compile(opts.WSOrigin); err != nil {
return fmt.Errorf("invalid WSOrigin %q: %w", opts.WSOrigin, err)
} Try / catch
srv, err := server.New(factory, opts)
if err != nil {
log.Fatalf("WSOrigin regex invalid: %v", err)
} Prevention
- Validate WSOrigin regex at config-load time, before starting the server
- Keep patterns simple and test them in a regex tool with RE2 semantics
- Escape dots in hostnames: use \. not .
When it happens
Trigger: Calling server.New() with Options.WSOrigin set to a string that is not a valid regular expression (e.g. "*.example.com", "(foo", "[a-z").
Common situations: Putting glob-style wildcards in WSOrigin instead of regex syntax; copying a shell-quoted value with stray backslashes; unbalanced parentheses when listing multiple origins like "(a.com|b.com".
Related errors
- failed to setup an HTTP server
- failed to setup TLS configuration
- could not open CA crt file %s
- Error: No command given.
- invalid bool expression: %v, use true/false
AI-assisted analysis of yudai/gotty@a080c85cbc (2026-09-02).
Data as JSON: /api/errors/f581befd8a612d8e.
Report an issue: GitHub.