-
Notifications
You must be signed in to change notification settings - Fork 222
refactor: new error system #624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8cf6efb
refactor: new error system
alejandro-vaz 7864d3e
fix: remove never type
alejandro-vaz 4c5cd97
fix: precise lint
alejandro-vaz 7ba7814
refactor: change to infallible
alejandro-vaz 9553b24
fix: style formatting
alejandro-vaz fb2e818
refactor: include in-string formatting
alejandro-vaz e6592c2
Merge branch 'v2' into new-errors
alejandro-vaz 56a6eb9
fix: error handling
alejandro-vaz e5c0c96
fix: remove crate import prefix
alejandro-vaz cbd5613
refactor: simplified errors
alejandro-vaz 35321b2
refactor: add handle inline
alejandro-vaz 1852ed3
style: formatting
alejandro-vaz 94bdf72
refactor: cleaner error handling
alejandro-vaz b9124b9
fix: unreachable code
alejandro-vaz ebeb461
refactor: reorder implementations
alejandro-vaz 15363ce
refactor: error method
alejandro-vaz b4b3849
refactor: remove comment
alejandro-vaz 8c6c21b
style: formatting
alejandro-vaz 060f271
fix: added attributes to error handling
alejandro-vaz 28f0426
fix: remove smallvec word from error message
alejandro-vaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,38 @@ | ||
| use core::alloc::Layout; | ||
| use { | ||
| alloc::alloc::handle_alloc_error, | ||
| core::{ | ||
| alloc::Layout, | ||
| error::Error, | ||
| fmt::{ | ||
| Debug, | ||
| Display, | ||
| Formatter, | ||
| Result as Format | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| /// Error type for APIs with fallible heap allocation | ||
| #[derive(Debug)] | ||
| pub enum CollectionAllocErr { | ||
| /// Overflow `usize::MAX` or other error during size computation | ||
| pub enum SmallVecError { | ||
| CapacityOverflow, | ||
| /// The allocator return an error | ||
| AllocErr { | ||
| /// The layout that was passed to the allocator | ||
| layout: Layout | ||
| } | ||
| AllocationError(Layout) | ||
| } | ||
| impl core::fmt::Display for CollectionAllocErr { | ||
| fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
| write!(f, "Allocation error: {:?}", self) | ||
|
|
||
| impl Display for SmallVecError { | ||
| fn fmt(&self, f: &mut Formatter<'_>) -> Format { | ||
| write!(f, "Allocation error: {self:?}") | ||
| } | ||
| } | ||
|
|
||
| impl core::error::Error for CollectionAllocErr {} | ||
| impl Error for SmallVecError {} | ||
|
|
||
| impl SmallVecError { | ||
| #[cold] | ||
| #[inline(never)] | ||
| pub fn handle<Type>(self) -> Type { | ||
| match self { | ||
| SmallVecError::CapacityOverflow => panic!("capacity overflow"), | ||
| SmallVecError::AllocationError(layout) => handle_alloc_error(layout) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.