feat: update error notes for wfassoc
This commit is contained in:
1 parent
1a44240f88
commit
880f90211b
8 files changed
+58
-47
No files matched your search
@@ -17,37 +17,36 @@ use thiserror::Error as TeError;
|
||||
/// Error occurs when trying converting [Schema] into [Program].
|
||||
#[derive(Debug, TeError)]
|
||||
pub enum ParseProgramError {
|
||||
#[error("{0}")]
|
||||
#[error("parsing into Program error: {0}")]
|
||||
BadExtBody(#[from] concept::BadExtBodyError),
|
||||
#[error("{0}")]
|
||||
#[error("parsing into Program error: {0}")]
|
||||
BadProgIdPart(#[from] concept::BadProgIdPartError),
|
||||
#[error("{0}")]
|
||||
#[error("parsing into Program error: {0}")]
|
||||
BadFileName(#[from] concept::BadFileNameError),
|
||||
#[error("{0}")]
|
||||
#[error("parsing into Program error: {0}")]
|
||||
ParseCmdLine(#[from] concept::ParseCmdLineError),
|
||||
#[error("{0}")]
|
||||
#[error("parsing into Program error: {0}")]
|
||||
CastOsStr(#[from] utilities::CastOsStrError),
|
||||
#[error("given path doesn't has legal file name part")]
|
||||
|
||||
#[error("given path doesn't has legal file name part when parsing into Program")]
|
||||
NoFileNamePart,
|
||||
#[error("given path doesn't has legal directory part")]
|
||||
#[error("given path doesn't has legal directory part when parsing into Program")]
|
||||
NoDirNamePart,
|
||||
#[error("given identifier is not presented in dict")]
|
||||
NoSuchIdentifier,
|
||||
#[error("extension name should not be empty")]
|
||||
EmptyExtension,
|
||||
#[error("given program identifier is not allowed")]
|
||||
#[error("identifier {0} is unexpected not presented in HashMap when parsing into Program")]
|
||||
NoSuchIdentifier(String),
|
||||
#[error("bad program identifier found when parsing into Program")]
|
||||
BadIdentifier,
|
||||
}
|
||||
|
||||
/// Error occurs when operating with [Program].
|
||||
#[derive(Debug, TeError)]
|
||||
pub enum ProgramError {
|
||||
#[error("{0}")]
|
||||
#[error("Program operation error: {0}")]
|
||||
Lowlevel(#[from] lowlevel::Error),
|
||||
#[error("{0}")]
|
||||
#[error("Program operation error: {0}")]
|
||||
LoadIconRc(#[from] concept::LoadIconRcError),
|
||||
#[error("given index is invalid")]
|
||||
BadIndex,
|
||||
#[error("given file extension index {0} is invalid when visiting Program")]
|
||||
BadIndex(usize),
|
||||
}
|
||||
|
||||
// endregion
|
||||
@@ -129,7 +128,7 @@ impl Program {
|
||||
.get(*index)
|
||||
.expect("unexpected invalid index")
|
||||
.clone()),
|
||||
None => Err(ParseProgramError::NoSuchIdentifier),
|
||||
None => Err(ParseProgramError::NoSuchIdentifier(key.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,7 +321,10 @@ impl Program {
|
||||
|
||||
pub fn resolve_ext(&self, index: usize) -> Result<ProgramSelfExtStatus, ProgramError> {
|
||||
// Fetch data
|
||||
let progid_ext_key = self.ext_keys.get(index).ok_or(ProgramError::BadIndex)?;
|
||||
let progid_ext_key = self
|
||||
.ext_keys
|
||||
.get(index)
|
||||
.ok_or(ProgramError::BadIndex(index))?;
|
||||
|
||||
// Try resolving name with string resource first,
|
||||
// and fallback to ProgId verbatim.
|
||||
@@ -507,7 +509,7 @@ impl Program {
|
||||
ext_key.ensure(scope)?;
|
||||
ext_key.set_default(scope, Some(progid_key.inner()))?;
|
||||
}
|
||||
None => return Err(ProgramError::BadIndex),
|
||||
None => return Err(ProgramError::BadIndex(index)),
|
||||
};
|
||||
|
||||
// Everything is okey.
|
||||
@@ -529,7 +531,7 @@ impl Program {
|
||||
ext_key.ensure(scope)?;
|
||||
ext_key.set_default(scope, None)?;
|
||||
}
|
||||
None => return Err(ProgramError::BadIndex),
|
||||
None => return Err(ProgramError::BadIndex(index)),
|
||||
}
|
||||
|
||||
// Everything is okey.
|
||||
@@ -597,7 +599,7 @@ impl Program {
|
||||
// Okey, return it.
|
||||
Ok(Some(ProgramExtStatus::new(name, icon)))
|
||||
}
|
||||
None => Err(ProgramError::BadIndex),
|
||||
None => Err(ProgramError::BadIndex(index)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use super::{Program, ParseProgramError};
|
||||
/// Error occurs when operating with [Schema].
|
||||
#[derive(Debug, TeError)]
|
||||
pub enum SchemaError {
|
||||
#[error("duplicate key: {0}")]
|
||||
#[error("duplicate key in Schema operation: {0}")]
|
||||
DuplicateKey(String),
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -10,27 +10,27 @@ use winreg::enums::{KEY_READ, KEY_WRITE};
|
||||
/// Error occurs in this module.
|
||||
#[derive(Debug, TeError)]
|
||||
pub enum Error {
|
||||
#[error("can not perform this operation because lack essential privilege")]
|
||||
#[error("some lowlevel operations require escalating privilege")]
|
||||
NoPrivilege,
|
||||
#[error("given registry key is inexistant")]
|
||||
#[error("given lowlevel registry key is not presented")]
|
||||
InexistantKey,
|
||||
|
||||
#[error("registry operation error: {0}")]
|
||||
#[error("lowlevel registry operation error: {0}")]
|
||||
BadRegOp(#[from] std::io::Error),
|
||||
#[error("{0}")]
|
||||
#[error("unexpected blank registry key in lowlevel registry operation")]
|
||||
UnexpectedBlankKey(#[from] regext::BlankPathError),
|
||||
|
||||
#[error("{0}")]
|
||||
#[error("lowlevel operation error: {0}")]
|
||||
ExpandEnvVar(#[from] concept::ExpandEnvVarError),
|
||||
#[error("{0}")]
|
||||
#[error("lowlevel operation error: {0}")]
|
||||
LoadIconRc(#[from] concept::LoadIconRcError),
|
||||
#[error("{0}")]
|
||||
#[error("lowlevel operation error: {0}")]
|
||||
LoadStrRc(#[from] concept::LoadStrRcError),
|
||||
#[error("{0}")]
|
||||
#[error("lowlevel operation error: {0}")]
|
||||
ParseVerb(#[from] concept::ParseVerbError),
|
||||
#[error("{0}")]
|
||||
#[error("lowlevel operation error: {0}")]
|
||||
ParseCmdLine(#[from] concept::ParseCmdLineError),
|
||||
#[error("{0}")]
|
||||
#[error("lowlevel operation error: {0}")]
|
||||
ParseExt(#[from] concept::ParseExtError),
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use thiserror::Error as TeError;
|
||||
|
||||
/// The error occurs when casting `OsStr` into `str`.
|
||||
#[derive(Debug, TeError)]
|
||||
#[error("fail to cast OS string into string")]
|
||||
#[error("fail to cast OS string into Rust string")]
|
||||
pub struct CastOsStrError {}
|
||||
|
||||
impl CastOsStrError {
|
||||
|
||||
@@ -42,6 +42,8 @@ impl Ext {
|
||||
/// Create an new file extension.
|
||||
///
|
||||
/// `body` is the body of file extension (excluding dot, such as `jpg`).
|
||||
/// Empty body is not allowed.
|
||||
///
|
||||
/// If you want to create this struct with ordinary extension string like `.jpg`,
|
||||
/// please use `Ext::from_str()` or `parse::<Ext>()` instead.
|
||||
pub fn new(body: &str) -> Result<Self, BadExtBodyError> {
|
||||
@@ -56,11 +58,17 @@ impl Ext {
|
||||
}
|
||||
|
||||
/// Get the body part of file extension (excluding dot)
|
||||
///
|
||||
/// This struct promise that there is no possibility that return value is blank
|
||||
/// (i.e. the body of file extension is empty).
|
||||
pub fn inner(&self) -> &str {
|
||||
&self.body
|
||||
}
|
||||
|
||||
/// Get the body part of file extension (with leading dot)
|
||||
///
|
||||
/// This struct promise that there is no possibility that return value is dot only
|
||||
/// (i.e. the body of file extension is empty).
|
||||
pub fn dotted_inner(&self) -> String {
|
||||
// Reuse Display trait result
|
||||
self.to_string()
|
||||
|
||||
Reference in new issue
Block a user