mirror of
https://github.com/theryangeary/choose
synced 2024-11-23 03:13:04 +00:00
Make regex compilation errors more specific
This commit is contained in:
parent
59ada49afd
commit
94085bb302
1 changed files with 22 additions and 7 deletions
|
@ -49,15 +49,30 @@ impl Config {
|
|||
}
|
||||
}
|
||||
|
||||
let separator = Regex::new(match &opt.field_separator {
|
||||
let separator = match Regex::new(match &opt.field_separator {
|
||||
Some(s) => s,
|
||||
None => "[[:space:]]",
|
||||
})
|
||||
.unwrap_or_else(|e| {
|
||||
eprintln!("Failed to compile regular expression: {}", e);
|
||||
// Exit code of 1 means failed to compile field_separator regex
|
||||
process::exit(1);
|
||||
});
|
||||
}) {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
// Exit code of 1 means failed to compile field_separator regex
|
||||
match e {
|
||||
regex::Error::Syntax(e) => {
|
||||
eprintln!("Syntax error compiling regular expression: {}", e);
|
||||
process::exit(1);
|
||||
}
|
||||
regex::Error::CompiledTooBig(e) => {
|
||||
eprintln!("Compiled regular expression too big: compiled size cannot exceed {} bytes", e);
|
||||
process::exit(1);
|
||||
}
|
||||
_ => {
|
||||
eprintln!("Error compiling regular expression: {}", e);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Config { opt, separator }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue