-
Notifications
You must be signed in to change notification settings - Fork 403
Refactor Win32Error to use std::system_error #919
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 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cd05f11
Refactor Win32Error (now SysError) to be portable using std::system_e…
Xebeth 52dc193
Replace Win32Error with SysError
Xebeth 9b2e6a6
Update the Unreal submodule to point to feature/sys-error-msg
Xebeth 0f55683
Fix casing of variables and members
Xebeth 90db2ca
refactor(helpers): improve SysError cross-platform implementation
narknon 1b4faac
Update Unreal submodule
UE4SS 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
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
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 |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| #pragma once | ||
|
|
||
| #include <system_error> | ||
|
|
||
| namespace RC | ||
| { | ||
| inline const std::error_category& default_error_category() noexcept | ||
| { | ||
| #ifdef _WIN32 | ||
| return std::system_category(); | ||
| #else | ||
| return std::generic_category(); | ||
| #endif | ||
| } | ||
|
|
||
| #ifdef _WIN32 | ||
| using PlatformResultCode = HRESULT; | ||
| #else | ||
| using PlatformResultCode = int; | ||
| #endif | ||
| } | ||
|
|
||
| namespace RC | ||
| { | ||
| /** | ||
| * Wrapper for error messages from system error code to be used as a string object | ||
| */ | ||
| class SysError | ||
| { | ||
| public: | ||
| /** | ||
| * Constructor for error code | ||
| * @param error_code : a system error code | ||
| * @param category : the error category (std::system_category() for OS specific codes or std::generic_category() for POSIX codes) | ||
| */ | ||
| explicit SysError(int error_code, const std::error_category& category = default_error_category()); | ||
| /** | ||
| * Constructor for error code | ||
| * @param error_code : a system error code | ||
| * @param category : the error category (std::system_category() for OS specific codes or std::generic_category() for POSIX codes) | ||
| */ | ||
| explicit SysError(unsigned long error_code, const std::error_category& category = default_error_category()); | ||
| /** | ||
| * Assign an error code and update the object with the corresponding error message | ||
| * @param error_code : a system error code | ||
| */ | ||
| auto assign(unsigned long error_code) -> void; | ||
| #ifdef _WIN32 | ||
| /** | ||
| * Constructor for COM HRESULT codes -- only works for FACILITY_WIN32 | ||
| * @param hresult : a COM operation result code | ||
| */ | ||
| explicit SysError(HRESULT hresult); | ||
|
|
||
| /** | ||
| * Assign an error code and update the object with the corresponding error message | ||
| * @param hresult : a COM operation result code | ||
| */ | ||
| auto assign(HRESULT hresult) -> void; | ||
| #endif | ||
| /** | ||
| * Returns a pointer to an array that contains a null-terminated sequence of characters representing the current value of the string object | ||
| * @return a pointer to the c-string representation of the string object's value | ||
| */ | ||
| [[nodiscard]] auto c_str() const noexcept -> const CharType* { return m_error_text.c_str(); } | ||
| /** | ||
| * Returns the name of the error category | ||
| * @return the name of the error category | ||
| */ | ||
| [[nodiscard]] auto category() const -> StringType; | ||
| /** | ||
| * Explicit cast operator to const CharType* | ||
| */ | ||
| explicit operator const CharType*() const noexcept { return c_str(); } // must be explicit, or it will cause an ambiguous call to overloaded function error when passed to RC::to_string | ||
| /** | ||
| * Implicit cast operator to const StringType& so that the wrapper can be passed to RC::to_string, for instance | ||
| */ | ||
| operator const StringType&() const noexcept { return m_error_text; } | ||
| private: | ||
| /** | ||
| * Formats the error message corresponding to the specified error code. | ||
| * @param error_code : a system error code or COM error code | ||
| * @return a string containing the formatted message, if successful | ||
| */ | ||
| [[nodiscard]] auto format_error(int error_code) const -> StringType; | ||
| /** | ||
| * The error category (std::system_category() for OS specific codes or std::generic_category() for POSIX codes) | ||
| */ | ||
| const std::error_category* m_error_category = nullptr; | ||
| /** | ||
| * The string object backing the wrapper | ||
| */ | ||
| StringType m_error_text; | ||
| }; | ||
| } | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My Windows installation is borked at the moment. I'll try to rerun the unit tests asap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test suite is all OK.