#[non_exhaustive]pub enum Error {
Show 18 variants
FileNotFound {
file: String,
},
InvalidMagic {
context: MagicContext,
},
InvalidCheckSum {
file: String,
computed: [u8; 16],
},
BadDecryptKey,
WrongPasscode,
BadEncryptedDataSize {
size: usize,
},
BadDecryptedDataSize {
encrypted_size: usize,
full_len: usize,
decrypted_size: usize,
},
BadConfigData {
context: ConfigFailure,
},
QDataStreamFailed {
context: Option<&'static str>,
},
ReadMapDataFailed {
context: MapReadFailure,
},
ReadMapDataIncorrectPasscode,
AuthKeyNotFound,
MaxAccountLimit,
SaveFailed,
KeyDataInvalid {
context: KeyDataFailure,
},
BadLength {
what: &'static str,
expected: usize,
actual: usize,
},
InvalidInput {
what: &'static str,
reason: String,
},
Io(Error),
}Expand description
Every failure the core can report.
Variants map 1:1 onto the tdata exceptions of the Python package
(opentele2.exception), plus Error::BadLength, Error::InvalidInput
and Error::Io. Bindings
dispatch on Error::code, which is stable across releases; the
Display text is for humans and may change. Error::legacy_message
is the message of the matching exception, built from the context the
variants carry.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
FileNotFound
A required tdata file does not exist (TFileNotFound).
InvalidMagic
A tdata file does not start with the TDF$ magic, or the MTP data
holds an unknown block (TDataInvalidMagic).
Fields
context: MagicContextWhere the bad magic was found.
InvalidCheckSum
A tdata file’s MD5 checksum does not match its contents
(TDataInvalidCheckSum).
Fields
file: StringThe file name without its suffix; empty when the bytes were
parsed without a name (crate::tdf::TdfFile::parse).
BadDecryptKey
Decryption produced data that does not match its key (TDataBadDecryptKey).
WrongPasscode
The local passcode does not unlock the tdata (TDataWrongPasscode).
BadEncryptedDataSize
Encrypted data has a size that is not valid for AES-IGE
(TDataBadEncryptedDataSize).
BadDecryptedDataSize
Decrypted data declares a size that does not fit the buffer
(TDataBadDecryptedDataSize).
Fields
BadConfigData
The config block of a tdata file cannot be parsed (TDataBadConfigData).
Fields
context: ConfigFailureWhich check of the config failed.
QDataStreamFailed
A QDataStream read or write failed (QDataStreamFailed).
Fields
ReadMapDataFailed
The account map data cannot be read (TDataReadMapDataFailed).
Fields
context: MapReadFailureWhich step of the read failed.
ReadMapDataIncorrectPasscode
The account map data was read with an incorrect passcode
(TDataReadMapDataIncorrectPasscode).
AuthKeyNotFound
No authorization key was found in the tdata (TDataAuthKeyNotFound).
MaxAccountLimit
The account limit of Telegram Desktop is reached (MaxAccountLimit).
SaveFailed
Writing the tdata failed (TDataSaveFailed).
KeyDataInvalid
The key_<dataName> file is malformed or uses parameters that cannot
make a passcode key (TDataKeyDataInvalid).
Fields
context: KeyDataFailureWhich check of the key data failed.
BadLength
A buffer, key, or IV has the wrong length.
Fields
InvalidInput
A caller-supplied argument is outside what the operation accepts, for
a reason other than its length (that is Error::BadLength).
Fields
Io(Error)
An I/O operation on a caller-supplied path failed.
Implementations§
Source§impl Error
impl Error
Sourcepub fn code(&self) -> &'static str
pub fn code(&self) -> &'static str
Stable SCREAMING_SNAKE code identifying the variant, for example
"TDATA_WRONG_PASSCODE". Bindings map this code onto their own error
types; it never changes for an existing variant.
Sourcepub fn detail_code(&self) -> Option<&'static str>
pub fn detail_code(&self) -> Option<&'static str>
Stable SCREAMING_SNAKE code of the context of an error whose
context a binding raises differently from the rest of its
Error::code, else None. It never changes once given.
"BAD_ACCOUNTS_COUNT":Error::KeyDataInvalidwithKeyDataFailure::BadAccountsCount, which is raised as a plainOpenTeleExceptionrather thanTDataKeyDataInvalid.
Every other error has no detail code.
Sourcepub fn legacy_message(&self) -> String
pub fn legacy_message(&self) -> String
The message of the matching exception (its message attribute,
without the class name and caller str() adds), for
example Invalid magic b'ABCD' in file maps.
Error::FileNotFound:Could not open {file}.Error::InvalidMagic:Invalid magic {magic!r} in file {file}, the magic as a Pythonbytesliteral; for an MTP data blockUnsupported block id in MtpData: {block_id}.Error::InvalidCheckSum:Invalid checksum {md5 hex} in file {file}.Error::BadEncryptedDataSizeandError::BadDecryptedDataSize: theStorage.DecryptLocalmessages with their sizes.Error::BadDecryptKey: theStorage.DecryptLocalmessage, for key-data steps too.Error::QDataStreamFailed: the context, else the defaultCould not stream data.Error::ReadMapDataFailed,Error::ReadMapDataIncorrectPasscode,Error::AuthKeyNotFoundandError::MaxAccountLimit: theMapData.read,_findMainAuthKeyandFromTelethonmessages.Error::KeyDataInvalid: theread_key_data,create_passcode_keyand__loadFromTDatamessage of its context.Error::SaveFailed:Could not save tdata, something went wrong, the one message ofSaveTData.Error::BadConfigData: theconstructFromSerialized,MTP.Config.FromSerialized,MTP.Config.endpointsandFromTDesktopmessage of its context (for the IP and environment checks the Python 3.8UnicodeDecodeErrorandValueErrortext), and a plain description for the endpoint, session and self-user checks.
Error::WrongPasscode, Error::BadLength,
Error::InvalidInput (Invalid {what}: {reason}) and Error::Io
give their Display text.
Sourcepub fn legacy_class(&self) -> &'static str
pub fn legacy_class(&self) -> &'static str
The class name of the exception raised for the failure, the
single source the bindings name their errors after (the Python
CORE_ERROR_TYPES table, the Node error name).
Each tdata variant gives the opentele2.exception class its doc
names, for example TDataWrongPasscode; Error::KeyDataInvalid with
KeyDataFailure::BadAccountsCount (Error::detail_code
BAD_ACCOUNTS_COUNT) gives OpenTeleException. The variants with no
opentele2 class of their own give a Python builtin: ValueError for
Error::BadLength (as an AES-IGE backend raises) and
Error::InvalidInput (as hashlib does), OSError for
Error::Io.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Auto Trait Implementations§
impl !RefUnwindSafe for Error
impl !UnwindSafe for Error
impl Freeze for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more