Enum pelite::Error

source ·
pub enum Error {
    Null,
    Bounds,
    ZeroFill,
    Unmapped,
    Misaligned,
    BadMagic,
    PeMagic,
    Insanity,
    Invalid,
    Overflow,
    Encoding,
    Aliasing,
}
Expand description

Errors while parsing the PE binary.

Variants

Null

Null address.

Bounds

Out of bounds.

Catch-all for bounds check errors.

ZeroFill

Data is not available.

Can happen when referencing data in PeFile instances.

Sections can be shorter than stored on disk, the remaining bytes will default to zeroes when loaded by the system. Since these zeroes would just be a waste of space, they are not present in the binaries on disk. This error happens when attempting to get a reference to such zero filled data.

Unmapped

Data is not available.

Can happen when referencing data in PeView instances.

Sections can have excess in their raw data which won’t be mapped when loaded by the system. This error happens when attempting to get a reference to such unmapped raw data. Sometimes this kind of excess is called an overlay.

Misaligned

Address is misaligned.

BadMagic

Expected magic number does not match.

PeMagic

Trying to load a PE32 file with a PE32+ parser or vice versa.

Insanity

Sanity check failed.

Some value was so far outside its typical range, while not technically incorrect, probably indicating something went wrong. If this error is encountered legitimately, create an issue or file a PR to relax the artificial restrictions.

Invalid

Invalid data.

Structured data was found which simply isn’t valid. Catch-all for errors which don’t fall under other errors.

Overflow

Overflow error.

Catch-all for overflow and underflow errors.

Encoding

Encoding error.

Catch-all for string related errors such as lacking a nul terminator.

Aliasing

Aliasing error.

Request cannot be fulfilled because it would alias with an existing borrow.

Implementations

Returns if the error variant is Null.

Useful in match guards where Null should be handled as a non-error case.

fn with_default(result: pelite::Result<i32>) -> pelite::Result<i32> {
	let i = match result {
		Ok(i) => i,
		// Avoids a more verbose comparison with pelite::Error::Null
		Err(err) if err.is_null() => 0,
		Err(err) => return Err(err),
	};
	Ok(i)
}

assert_eq!(with_default(Err(pelite::Error::Null)), Ok(0));

Returns a simple string representation of the error.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
👎Deprecated since 1.42.0: use the Display impl or to_string()
The lower-level source of this error, if any. Read more
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type based access to context intended for error reports. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

🔬This is a nightly-only experimental API. (provide_any)
Data providers should implement this method to provide all values they are able to provide by using demand. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.