#pragma once /// \file errors.h /// \author Folling #include /// \addtogroup errors Errors /// \brief Error handling within libikarus /// \details Functions in Ikarus may fail. To report the type of failure all functions have an out parameter for the error. /// Upon erring the function will store relevant information about the error in /// the out parameter. If the out parameter is null nothing will be stored. This /// is not recommended as it essentially ignores errors. For the sake of /// simplicity we have avoided mechanisms that "force" clients to handle errors. /// @{ IKARUS_BEGIN_HEADER /// \brief Delineates what caused an error. /// \remark Note that this doesn't show responsibility. An error with source "SubSystem" could still be the /// fault of libikarus, it just indicates where the error occurred. enum IkarusErrorInfo { /// \brief No error occurred. IkarusErrorInfo_None = 0x0, /// \brief The client misused the API. /// Example: Accessing a resource that does not exist. 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 = 0x01000002, /// \brief The client provided a non-existent resource. /// Example: Passing an entity to a function after it has been deleted. IkarusErrorInfo_Client_NonExistent = 0x01000003, /// \brief The client provided a resource which exists but is not linked to the current context. /// Example: Passing a property that isn't linked to the current entity. IkarusErrorInfo_Client_NotLinked = 0x01000004, /// \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 = 0x01000005, /// \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 = 0x01000006, /// \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 = 0x01000007, /// \brief The client provided valid data in an invalid format. /// Example: Passing a malformed JSON string. IkarusErrorInfo_Client_InvalidFormat = 0x01000008, /// \brief The client violated a constraint. /// \details This error is most likely caused by clients. /// Example: A user tries to set the age of a character to a value outside /// its specified range. IkarusErrorInfo_Client_ConstraintViolated = 0x10000009, // 0x02 reserved for dependency errors /// \brief A file was not found. IkarusErrorInfo_Filesystem_NotFound = 0x03000001, /// \brief A file or directory already exists. IkarusErrorInfo_Filesystem_AlreadyExists = 0x03000002, /// \brief Missing permissions to access a file or directory. IkarusErrorInfo_Filesystem_MissingPermissions = 0x03000003, /// \brief Insufficient space to perform an operation. IkarusErrorInfo_Filesystem_InsufficientSpace = 0x03000004, /// \brief A path is invalid. IkarusErrorInfo_Filesystem_InvalidPath = 0x03000005, /// \brief A database connection failed. IkarusErrorInfo_Database_ConnectionFailed = 0x04000001, /// \brief A database query failed. IkarusErrorInfo_Database_QueryFailed = 0x04000002, /// \brief A database migration failed. 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-existent blueprint. IkarusErrorInfo_Database_InvalidState = 0x04000004, /// \brief A system call failed. IkarusErrorInfo_OS_SystemCallFailed = 0x05000001, /// \brief A system call returned an invalid value. IkarusErrorInfo_OS_InvalidReturnValue = 0x05000002, /// \brief An OOM error occurred. 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 = 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 = 0x06000003, }; /// \brief The maximum length of an error message. #define IKARUS_ERROR_DATA_MAX_MESSAGE_LIMIT 128 /// \brief The data stored for an error struct IkarusErrorData { /// \brief The error type enum IkarusErrorInfo info; char message[IKARUS_ERROR_DATA_MAX_MESSAGE_LIMIT]; }; /// \brief Gets the name of an error info. /// \param info The error info to get the name of. /// \return The name of the error info. /// \remark The returned pointer is valid for the lifetime of the program and must not be freed. IKA_API char const * ikarus_error_info_get_name(enum IkarusErrorInfo info); /// \brief Checks if an error data is a success. /// \param data The error data to check. /// \return True if the error data is a success, false otherwise. IKA_API bool ikarus_error_data_is_success(IkarusErrorData const * data); /// \brief Checks if an error data is an error. /// \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); IKARUS_END_HEADER /// @}