{"record":{"id":"21781c82566d5249","repo":"iawia002/lux","slug":"errinvalidregularexpression","errorCode":"ErrInvalidRegularExpression","errorMessage":"invalid regular expression","messagePattern":"invalid regular expression","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"extractors/errors.go","lineNumber":10,"sourceCode":"package extractors\n\nimport (\n\t\"errors\"\n)\n\nvar (\n\t// ErrURLParseFailed defines url parse failed error.\n\tErrURLParseFailed            = errors.New(\"url parse failed\")\n\tErrInvalidRegularExpression  = errors.New(\"invalid regular expression\")\n\tErrURLQueryParamsParseFailed = errors.New(\"url query params parse failed\")\n\tErrBodyParseFailed           = errors.New(\"body parse failed\")\n)\n","sourceCodeStart":1,"sourceCodeEnd":14,"githubUrl":"https://github.com/iawia002/lux/blob/dd00f6d258d80b6684a0b9402d7124e5c18ef42f/extractors/errors.go#L1-L14","documentation":"Sentinel returned when a runtime regexp.Compile inside an extractor fails. The only throw site in the tree is pornhub.go:83, where the constant script-tag pattern fails to compile. Because the pattern is hardcoded and valid, this is essentially a maintenance-time defect: it only fires if someone edits the pattern into an invalid expression, and the sentinel then hides the real compile message.","triggerScenarios":"A contributor edits the pornhub script regex into a malformed expression (unbalanced parens, bad escapes); no user input reaches this path.","commonSituations":"Hand-edits to extractor regexes without running tests; refactors that touch the pattern string.","solutions":["When editing the pattern, test it in isolation with regexp.MustCompile first.","Return the underlying compile error instead of the sentinel so the real problem surfaces.","Move the pattern to a package-level regexp.MustCompile so a bad regex fails at build/test time, not at runtime."],"exampleFix":"// before\nreg, err := regexp.Compile(`<script\\b[^>]*>([\\s\\S]*?)</script>`)\nif err != nil {\n\treturn nil, errors.WithStack(extractors.ErrInvalidRegularExpression)\n}\n// after — compile once at package scope; bad patterns fail at build/test time\nvar scriptRe = regexp.MustCompile(`<script\\b[^>]*>([\\s\\S]*?)</script>`)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isInvalidRegularExpression(err error) bool {\n\treturn errors.Is(err, extractors.ErrInvalidRegularExpression)\n}","tryCatchPattern":"If caught, treat it as a code defect, not a runtime condition: report it upstream with the extractor name; there is no input-level remedy.","preventionTips":["Prefer package-level regexp.MustCompile so bad patterns fail at build time","Return the underlying compile error instead of the sentinel in library code","Add unit tests covering every regex an extractor relies on"],"tags":["pornhub","regex","sentinel-error","developer-error"],"backgroundTag":null,"analyzedSha":"dd00f6d258d80b6684a0b9402d7124e5c18ef42f","analyzedAt":"2026-08-15T16:57:31.080Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}