{"record":{"id":"1b512f4cba7d38e0","repo":"can1357/oh-my-pi","slug":"invalid-regular-expression-0","errorCode":null,"errorMessage":"invalid regular expression: {0}","messagePattern":"invalid regular expression: (.+?)","errorType":"error_code","errorClass":"TacError","httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/tac.rs","lineNumber":30,"sourceCode":"use clap::{Arg, ArgAction, ArgMatches, Command};\nuse memchr::memmem;\nuse memmap2::Mmap;\nuse thiserror::Error;\nuse uucore::display::Quotable;\n\nuse crate::host::{Host, Utility, format_usage, matches_parser, util};\n\nmod options {\n\tpub static BEFORE: &str = \"before\";\n\tpub static REGEX: &str = \"regex\";\n\tpub static SEPARATOR: &str = \"separator\";\n\tpub static FILE: &str = \"file\";\n}\n\n#[derive(Debug, Error)]\nenum TacError {\n\t/// A regular expression given by the user is invalid.\n\t#[error(\"invalid regular expression: {0}\")]\n\tInvalidRegex(regex::Error),\n\t/// An error opening a file for reading.\n\t#[error(\"failed to open {} for reading: {}\", .0.quote(), strip_errno(.1))]\n\tOpen(OsString, std::io::Error),\n\t/// An error reading the contents of a file or stdin.\n\t#[error(\"{}: read error: {}\", .0.maybe_quote(), strip_errno(.1))]\n\tRead(OsString, std::io::Error),\n\t/// An error writing the reversed contents of a file or stdin.\n\t#[error(\"failed to write to stdout: {}\", strip_errno(.0))]\n\tWrite(std::io::Error),\n}\n\nfn strip_errno(error: &std::io::Error) -> String {\n\tlet mut message = error.to_string();\n\tif let Some(position) = message.find(\" (os error \") {\n\t\tmessage.truncate(position);\n\t}\n\tmessage","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/tac.rs#L12-L48","documentation":"This error from the tac builtin (crates/pi-builtins/src/tac.rs, InvalidRegex) means the separator expression supplied via tac's -r/--regex option failed to compile with the regex crate. tac reverses files using a user-provided separator pattern; an invalid pattern cannot be used. The regex::Error is embedded and describes the exact syntax problem.","triggerScenarios":"Running tac with `-r/--regex` and a pattern that fails regex compilation, e.g. `tac -r '[unclosed'` or `tac -r 'a{2,1}'` (invalid repetition bounds).","commonSituations":"Hand-written patterns with unescaped special characters (`(`, `[`, `*` in the wrong place); shell quoting stripping backslashes (`tac -r '\\n'` semantics); patterns ported from other regex dialects with unsupported syntax.","solutions":["Fix the regex syntax reported by the wrapped error (e.g. close the bracket, escape specials).","Test the pattern in a regex tool (e.g. `regex` crate syntax) before passing it to tac.","If you meant a literal separator string, drop -r/--regex so the argument is treated literally.","Quote the pattern properly in the shell: use single quotes to avoid backslash mangling."],"exampleFix":"// before\ntac -r '[sep]'  // invalid regular expression: unclosed character class\n\n// after\ntac -r '\\[sep\\]'","handlingStrategy":"validation","validationCode":"const { Regex } = require('regex');\nfunction isValidRegex(pattern) {\n  try { new Regex(pattern); return true; } catch { return false; }\n}","typeGuard":"function isInvalidRegexError(err) {\n  return err instanceof Error && err.message.startsWith('invalid regular expression: ');\n}","tryCatchPattern":"try {\n  await tac.run(['-r', pattern, file]);\n} catch (err) {\n  if (String(err).startsWith('invalid regular expression')) {\n    console.error(`bad separator pattern '${pattern}', falling back to literal newline`);\n  } else throw err;\n}","preventionTips":["Compile-test patterns with the regex crate syntax before passing to tac -r.","Quote regex arguments with single quotes in shell to protect backslashes.","Only use -r/--regex when a pattern is actually needed; literal separators work without it."],"tags":["regex","tac","input-validation"],"backgroundTag":"invalid-regex","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}