Skip to content

Commit

Permalink
Add context to Error::DecodeError
Browse files Browse the repository at this point in the history
Unfortunately esplugin doesn't expose similar context, so decode errors
it reports are handled as generic plugin parsing errors. A future
esplugin update will provide that context, at which point libloadorder
can be updated to use it.
  • Loading branch information
Ortham committed Nov 25, 2023
1 parent d505a9f commit 7edd0e3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* along with libloadorder. If not, see <http://www.gnu.org/licenses/>.
*/

use std::borrow::Cow;
use std::convert::From;
use std::error;
use std::ffi::OsString;
Expand Down Expand Up @@ -81,7 +80,7 @@ pub enum Error {
NoFilename(PathBuf),
SystemTimeError(time::SystemTimeError),
NotUtf8(Vec<u8>),
DecodeError(Cow<'static, str>),
DecodeError(Vec<u8>),
EncodeError(String),
PluginParsingError(PathBuf),
PluginNotFound(String),
Expand Down Expand Up @@ -147,7 +146,7 @@ impl fmt::Display for Error {
write!(f, "The plugin path {path:?} has no filename part"),
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::DecodeError(bytes) => write!(f, "String could not be decoded from Windows-1252, bytes are {bytes:02X?}"),
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/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ where
// they get mapped to C1 control characters.
let decoded_content = WINDOWS_1252
.decode_without_bom_handling_and_without_replacement(&content)
.ok_or_else(|| Error::DecodeError("invalid sequence".into()))?;
.ok_or_else(|| Error::DecodeError(content.clone()))?;

Ok(decoded_content.lines().filter_map(line_mapper).collect())
}
Expand Down
4 changes: 1 addition & 3 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ fn file_error(file_path: &Path, error: esplugin::Error) -> Error {
esplugin::Error::ParsingIncomplete | esplugin::Error::ParsingError(_, _) => {
Error::PluginParsingError(file_path.to_path_buf())
}
esplugin::Error::DecodeError => {
Error::DecodeError("invalid byte sequence in plugin string".into())
}
esplugin::Error::DecodeError => Error::PluginParsingError(file_path.to_path_buf()),
}
}

Expand Down

0 comments on commit 7edd0e3

Please sign in to comment.