tracel-ai/burn · error
Invalid regex pattern
Error message
Invalid regex pattern
What it means
Regex validation guard in `with_remap_pattern`: the `from` string is compiled as a regex for key remapping; an invalid pattern makes `Regex::new` fail and the builder panics instead of silently accepting a broken remapper.
Source
Thrown at crates/burn-store/src/burnpack.rs:303
/// Set key remapper for tensor name transformations during loading
#[cfg(feature = "std")]
pub fn remap(mut self, remapper: KeyRemapper) -> Self {
self.remapper = remapper;
self
}
/// Add a single regex pattern for key remapping
#[cfg(feature = "std")]
pub fn with_remap_pattern<S1, S2>(mut self, from: S1, to: S2) -> Self
where
S1: AsRef<str>,
S2: Into<String>,
{
self.remapper = self
.remapper
.add_pattern(from.as_ref(), to.into())
.expect("Invalid regex pattern");
self
}
/// Set the path filter
pub fn filter(mut self, filter: PathFilter) -> Self {
self.filter = Some(filter);
self
}
/// Get the bytes after writing (only valid for bytes mode after collecting)
pub fn get_bytes(&self) -> Result<Bytes, PackError> {
// `collect_from` caches the written bytes back into `self.mode` for bytes mode.
match &self.mode {
StoreMode::Bytes(Some(bytes)) => Ok(bytes.clone()),
_ => Err(PackError::IoError("No bytes available".into())),
}
}
View on GitHub (pinned to d16f7ba2ed)
Solutions
- Validate the pattern with `Regex::new` before passing it
- Fix escaping of regex metacharacters (e.g., `.`, `(`, `*`) in the pattern
- Use `add_pattern` with error handling for fallible construction
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/burn-store/src/burnpack.rs:303 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/d1292eaa683bb76d.
Report an issue: GitHub.