fix up LanguageError
This commit is contained in:
parent
f055daa73d
commit
53ec92865b
|
@ -3,11 +3,11 @@ use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum LanguageError {
|
pub enum LanguageError {
|
||||||
#[error("Error(s) encountered encoding text from {0} to {1}")]
|
#[error("Error encoding string to {0} bytes")]
|
||||||
EncodeError(String, String),
|
EncodeError(String),
|
||||||
|
|
||||||
#[error("Error(s) encountered decoding text from {0} to {1}")]
|
#[error("Error decoding as {0} bytes")]
|
||||||
DecodeError(String, String),
|
DecodeError(String),
|
||||||
|
|
||||||
#[error("The number {0} does not correspond to any supported language")]
|
#[error("The number {0} does not correspond to any supported language")]
|
||||||
InvalidLanguageValue(u8),
|
InvalidLanguageValue(u8),
|
||||||
|
@ -50,10 +50,7 @@ impl Language {
|
||||||
let encoding = self.get_encoding();
|
let encoding = self.get_encoding();
|
||||||
let (cow, encoding_used, had_errors) = encoding.decode(bytes);
|
let (cow, encoding_used, had_errors) = encoding.decode(bytes);
|
||||||
if had_errors {
|
if had_errors {
|
||||||
Err(LanguageError::DecodeError(
|
Err(LanguageError::DecodeError(encoding_used.name().to_string()))
|
||||||
encoding.name().to_string(),
|
|
||||||
encoding_used.name().to_string(),
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(cow.to_string())
|
Ok(cow.to_string())
|
||||||
}
|
}
|
||||||
|
@ -63,10 +60,7 @@ impl Language {
|
||||||
let encoding = self.get_encoding();
|
let encoding = self.get_encoding();
|
||||||
let (cow, encoding_used, had_errors) = encoding.encode(s);
|
let (cow, encoding_used, had_errors) = encoding.encode(s);
|
||||||
if had_errors {
|
if had_errors {
|
||||||
Err(LanguageError::EncodeError(
|
Err(LanguageError::EncodeError(encoding_used.name().to_string()))
|
||||||
encoding.name().to_string(),
|
|
||||||
encoding_used.name().to_string(),
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(cow.to_vec())
|
Ok(cow.to_vec())
|
||||||
}
|
}
|
||||||
|
@ -112,7 +106,7 @@ mod tests {
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
Language::English.encode_text("東天の塔"),
|
Language::English.encode_text("東天の塔"),
|
||||||
Err(LanguageError::EncodeError(_, _))
|
Err(LanguageError::EncodeError(_))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue