Skip to content

Commit

Permalink
Add context to Error::EncodeError
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortham committed Nov 25, 2023
1 parent b4843fa commit d505a9f
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub enum Error {
SystemTimeError(time::SystemTimeError),
NotUtf8(Vec<u8>),
DecodeError(Cow<'static, str>),
EncodeError(Cow<'static, str>),
EncodeError(String),
PluginParsingError(PathBuf),
PluginNotFound(String),
TooManyActivePlugins {
Expand Down Expand Up @@ -148,7 +148,7 @@ impl fmt::Display for Error {
Error::SystemTimeError(error) => error.fmt(f),
Error::NotUtf8(bytes) => write!(f, "Expected a UTF-8 string, got bytes {bytes:02X?}"),
Error::DecodeError(_) => write!(f, "Text could not be decoded from Windows-1252"),
Error::EncodeError(_) => write!(f, "Text could not be encoded in Windows-1252"),
Error::EncodeError(string) => write!(f, "The string \"{string}\" could not be encoded to Windows-1252"),
Error::PluginParsingError(path) => {
write!(f, "An error was encountered while parsing the plugin at {path:?}")
}
Expand Down
2 changes: 1 addition & 1 deletion src/load_order/asterisk_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ mod tests {
load_order.plugins_mut().push(plugin);

match load_order.save().unwrap_err() {
Error::EncodeError(s) => assert_eq!("unrepresentable character", s),
Error::EncodeError(s) => assert_eq!("Blȧnk.esm", s),
e => panic!("Expected encode error, got {:?}", e),
};
}
Expand Down
4 changes: 1 addition & 3 deletions src/load_order/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ fn strict_encode(string: &str) -> Result<Cow<'_, [u8]>, Error> {
let (output, _, had_unmappable_chars) = WINDOWS_1252.encode(string);

if had_unmappable_chars {
Err(Error::EncodeError(Cow::Borrowed(
"unrepresentable character",
)))
Err(Error::EncodeError(string.to_string()))
} else {
Ok(output)
}
Expand Down
2 changes: 1 addition & 1 deletion src/load_order/textfile_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ mod tests {
load_order.plugins_mut().push(plugin);

match load_order.save().unwrap_err() {
Error::EncodeError(s) => assert_eq!("unrepresentable character", s),
Error::EncodeError(s) => assert_eq!("Blȧnk.esm", s),
e => panic!("Expected encode error, got {:?}", e),
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/load_order/timestamp_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ mod tests {
load_order.plugins_mut().push(plugin);

match load_order.save().unwrap_err() {
Error::EncodeError(s) => assert_eq!("unrepresentable character", s),
Error::EncodeError(s) => assert_eq!("Blȧnk.esm", s),
e => panic!("Expected encode error, got {:?}", e),
};
}
Expand Down

0 comments on commit d505a9f

Please sign in to comment.