implement remaining logic
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
e1bf97704a
commit
1ce811d566
41 changed files with 1393 additions and 408 deletions
|
|
@ -4,6 +4,7 @@
|
|||
/// \author Folling <folling@ikarus.world>
|
||||
|
||||
#include <ikarus/macros.h>
|
||||
#include <ikarus/stdtypes.h>
|
||||
|
||||
/// \addtogroup errors Errors
|
||||
/// \brief Error handling within libikarus
|
||||
|
|
@ -24,94 +25,81 @@ IKARUS_BEGIN_HEADER
|
|||
enum IkarusErrorInfo {
|
||||
/// \brief No error occurred.
|
||||
IkarusErrorInfo_None = 0x0,
|
||||
/// \brief The error was caused by the client.
|
||||
IkarusErrorInfo_Client = 0x10100000,
|
||||
/// \brief The error was caused by a dependency (e.g. boost) of libikarus.
|
||||
IkarusErrorInfo_Dependency = 0x10200000,
|
||||
/// \brief The error was caused by the filesystem.
|
||||
IkarusErrorInfo_Filesystem = 0x10300000,
|
||||
/// \brief The error was caused by the database.
|
||||
IkarusErrorInfo_Database = 0x10400000,
|
||||
/// \brief The error was caused by the underlying OS.
|
||||
IkarusErrorInfo_OS = 0x10500000,
|
||||
/// \brief The error was caused by libikarus itself.
|
||||
IkarusErrorInfo_LibIkarus = 0x10600000,
|
||||
|
||||
/// \brief The client misused the API.
|
||||
/// Example: Accessing a resource that does not exist.
|
||||
IkarusErrorInfo_Client_Misuse = 0x10100001,
|
||||
IkarusErrorInfo_Client_Misuse = 0x01000001,
|
||||
/// \brief The client provided a null value for a parameter that must not be null.
|
||||
/// Example: Passing null for `ikarus_project_get_name`
|
||||
IkarusErrorInfo_Client_InvalidNull = 0x10100002,
|
||||
IkarusErrorInfo_Client_InvalidNull = 0x01000002,
|
||||
/// \brief The client provided an index that was out of bounds for some array.
|
||||
/// Example: Passing the index 3 for an `IkarusToggleValue` with size 3.
|
||||
IkarusErrorInfo_Client_IndexOutOfBounds = 0x10100003,
|
||||
IkarusErrorInfo_Client_IndexOutOfBounds = 0x01000003,
|
||||
/// \brief The client provided a numeric value that was out of bounds
|
||||
/// Example: Passing the value 2^32 to an i32 (might be passed as a string).
|
||||
IkarusErrorInfo_Client_ValueOutOfBounds = 0x10100004,
|
||||
IkarusErrorInfo_Client_ValueOutOfBounds = 0x01000004,
|
||||
/// \brief The client provided invalid input that doesn't fit in any of the other categories.
|
||||
/// Example: Passing an empty/blank string for a string that must be non-empty/-blank.
|
||||
IkarusErrorInfo_Client_InvalidInput = 0x10100005,
|
||||
IkarusErrorInfo_Client_InvalidInput = 0x01000005,
|
||||
/// \brief The client provided valid data in an invalid format.
|
||||
/// Example: Passing a malformed JSON string.
|
||||
IkarusErrorInfo_Client_InvalidFormat = 0x10100006,
|
||||
IkarusErrorInfo_Client_InvalidFormat = 0x01000006,
|
||||
/// \brief The client violated a constraint.
|
||||
/// \details This error is most likely caused by endusers.
|
||||
/// Example: A user tries to set the age of a character to an value outside of their specified range.
|
||||
IkarusErrorInfo_Client_ConstraintViolated = 0x10100007,
|
||||
IkarusErrorInfo_Client_ConstraintViolated = 0x10000007,
|
||||
|
||||
// 0x02 reserved for dependency errors
|
||||
|
||||
/// \brief A file was not found.
|
||||
IkarusErrorInfo_Filesystem_NotFound = 0x10300001,
|
||||
/// \brief A file or directory already exists.
|
||||
IkarusErrorInfo_Filesystem_AlreadyExists = 0x10300002,
|
||||
IkarusErrorInfo_Filesystem_AccessIssue = 0x03000001,
|
||||
/// \brief A file was not found.
|
||||
IkarusErrorInfo_Filesystem_NotFound = 0x03000002,
|
||||
/// \brief A file or directory already exists.
|
||||
IkarusErrorInfo_Filesystem_AlreadyExists = 0x03000003,
|
||||
/// \brief Missing permissions to access a file or directory.
|
||||
IkarusErrorInfo_Filesystem_MissingPermissions = 0x10300003,
|
||||
IkarusErrorInfo_Filesystem_MissingPermissions = 0x03000004,
|
||||
/// \brief Insufficient space to perform an operation.
|
||||
IkarusErrorInfo_Filesystem_InsufficientSpace = 0x10300004,
|
||||
IkarusErrorInfo_Filesystem_InsufficientSpace = 0x03000005,
|
||||
/// \brief A path is invalid.
|
||||
IkarusErrorInfo_Filesystem_InvalidPath = 0x10300005,
|
||||
IkarusErrorInfo_Filesystem_InvalidPath = 0x03000006,
|
||||
|
||||
/// \brief A database connection failed.
|
||||
IkarusErrorInfo_Database_ConnectionFailed = 0x10400001,
|
||||
IkarusErrorInfo_Database_ConnectionFailed = 0x04000001,
|
||||
/// \brief A database query failed.
|
||||
IkarusErrorInfo_Database_QueryFailed = 0x10400002,
|
||||
IkarusErrorInfo_Database_QueryFailed = 0x04000002,
|
||||
/// \brief A database migration failed.
|
||||
IkarusErrorInfo_Database_MigrationFailed = 0x10400003,
|
||||
IkarusErrorInfo_Database_MigrationFailed = 0x04000003,
|
||||
/// \brief A database is in an invalid state. This indicates a corrupt project.
|
||||
/// Example: An entity is linked to a non-existant blueprint.
|
||||
IkarusErrorInfo_Database_InvalidState = 0x10400004,
|
||||
IkarusErrorInfo_Database_InvalidState = 0x04000004,
|
||||
|
||||
/// \brief A system call failed.
|
||||
IkarusErrorInfo_OS_SystemCallFailed = 0x10500001,
|
||||
IkarusErrorInfo_OS_SystemCallFailed = 0x05000001,
|
||||
/// \brief A system call returned an invalid value.
|
||||
IkarusErrorInfo_OS_InvalidReturnValue = 0x10500002,
|
||||
IkarusErrorInfo_OS_InvalidReturnValue = 0x05000002,
|
||||
/// \brief An OOM error occurred.
|
||||
IkarusErrorInfo_OS_InsufficientMemory = 0x10500003,
|
||||
IkarusErrorInfo_OS_InsufficientMemory = 0x05000003,
|
||||
|
||||
/// \brief A datapoint within ikarus is invalid for the current state of the system.
|
||||
/// \details This differs from IkarusErrorInfo_Database_InvalidState in that the latter implies the database itself holds invalid state,
|
||||
/// whereas the former may imply that the state is ephemeral, e.g. data within a function.
|
||||
/// Example: The name of an object is found to be invalid UTF8.
|
||||
IkarusErrorInfo_LibIkarus_InvalidState = 0x20030001,
|
||||
IkarusErrorInfo_LibIkarus_InvalidState = 0x06000001,
|
||||
/// \brief libikarus is unable to perform a certain operation that should succeed.
|
||||
IkarusErrorInfo_LibIkarus_CannotPerformOperation = 0x06000002,
|
||||
/// \brief libikarus is unable to perform a certain operation within a given timeframe.
|
||||
/// Example: A query takes longer than the timeout.
|
||||
IkarusErrorInfo_LibIkarus_Timeout = 0x20030003,
|
||||
IkarusErrorInfo_LibIkarus_Timeout = 0x06000003,
|
||||
};
|
||||
|
||||
/// \brief The data limits for an error.
|
||||
enum IkarusErrorDataLimit {
|
||||
/// \brief The maximum number of error infos that can be stored in an error.
|
||||
IkarusErrorDataLimit_MaxErrorInfos = 8,
|
||||
/// \brief The maximum length of an error message.
|
||||
IkarusErrorDataLimit_MaxMessageLength = 128,
|
||||
};
|
||||
size_t const IKARUS_ERROR_DATA_MAX_MESSAGE_LIMIT = 128;
|
||||
|
||||
/// \brief The data stored for an error
|
||||
struct IkarusErrorData {
|
||||
/// \brief The scope of the error.
|
||||
/// \details This array may at most hold #IkarusErrorDataLimit_MaxErrorInfos elements.
|
||||
/// The first occurrence of #IkarusErrorInfo_None signifies the end of the array. If this happens at idx x== 0, no error occurred.
|
||||
IkarusErrorInfo infos[IkarusErrorDataLimit_MaxErrorInfos];
|
||||
/// \brief The error type
|
||||
IkarusErrorInfo info;
|
||||
|
||||
char message[IkarusErrorDataLimit_MaxMessageLength];
|
||||
char message[IKARUS_ERROR_DATA_MAX_MESSAGE_LIMIT];
|
||||
};
|
||||
|
||||
/// \brief Gets the name of an error info.
|
||||
|
|
@ -128,11 +116,6 @@ IKA_API bool ikarus_error_data_is_success(IkarusErrorData const * data);
|
|||
/// \param data The error data to check.
|
||||
/// \return True if the error data is an error, false otherwise.
|
||||
IKA_API bool ikarus_error_data_is_error(IkarusErrorData const * data);
|
||||
/// \brief Formats the error data in a reasonable but unspecified way.
|
||||
/// \param data The error data to format.
|
||||
/// \return The formatted error data.
|
||||
/// \remark Ownership of the returned pointer is passed to the user and must be freed at their leisure using ikarus_free.
|
||||
IKA_API char const * ikarus_error_data_pretty_format(IkarusErrorData const * data);
|
||||
|
||||
IKARUS_END_HEADER
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue