{"record":{"id":"f581befd8a612d8e","repo":"yudai/gotty","slug":"failed-to-compile-regular-expression-of-websocket","errorCode":null,"errorMessage":"failed to compile regular expression of Websocket Origin: %s","messagePattern":"failed to compile regular expression of Websocket Origin: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/server.go","lineNumber":64,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"failed to read custom index file at `%s`\", path)\n\t\t}\n\t}\n\tindexTemplate, err := template.New(\"index\").Parse(string(indexData))\n\tif err != nil {\n\t\tpanic(\"index template parse failed\") // must be valid\n\t}\n\n\ttitleTemplate, err := noesctmpl.New(\"title\").Parse(options.TitleFormat)\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"failed to parse window title format `%s`\", options.TitleFormat)\n\t}\n\n\tvar originChekcer func(r *http.Request) bool\n\tif options.WSOrigin != \"\" {\n\t\tmatcher, err := regexp.Compile(options.WSOrigin)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"failed to compile regular expression of Websocket Origin: %s\", options.WSOrigin)\n\t\t}\n\t\toriginChekcer = func(r *http.Request) bool {\n\t\t\treturn matcher.MatchString(r.Header.Get(\"Origin\"))\n\t\t}\n\t}\n\n\treturn &Server{\n\t\tfactory: factory,\n\t\toptions: options,\n\n\t\tupgrader: &websocket.Upgrader{\n\t\t\tReadBufferSize:  1024,\n\t\t\tWriteBufferSize: 1024,\n\t\t\tSubprotocols:    webtty.Protocols,\n\t\t\tCheckOrigin:     originChekcer,\n\t\t},\n\t\tindexTemplate: indexTemplate,\n\t\ttitleTemplate: titleTemplate,","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/yudai/gotty/blob/a080c85cbc59226c94c6941ad8c395232d72d517/server/server.go#L46-L82","documentation":"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.","triggerScenarios":"Calling server.New() with Options.WSOrigin set to a string that is not a valid regular expression (e.g. \"*.example.com\", \"(foo\", \"[a-z\").","commonSituations":"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\".","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"],"exampleFix":"// before\noptions.WSOrigin = \"*.example.com\"\n// after\noptions.WSOrigin = \".*\\.example\\.com\"","handlingStrategy":"validation","validationCode":"if _, err := regexp.Compile(opts.WSOrigin); err != nil {\n    return fmt.Errorf(\"invalid WSOrigin %q: %w\", opts.WSOrigin, err)\n}","typeGuard":null,"tryCatchPattern":"srv, err := server.New(factory, opts)\nif err != nil {\n    log.Fatalf(\"WSOrigin regex invalid: %v\", err)\n}","preventionTips":["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 ."],"tags":["regex","configuration","startup"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"a080c85cbc59226c94c6941ad8c395232d72d517","analyzedAt":"2026-09-02T16:42:38.150Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}