|
Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
|
Error handling for the runtime. More...
#include <stddef.h>Go to the source code of this file.
Data Structures | |
| struct | srn_error_t |
| A runtime error, a tag classifying the failure and a human-readable message. More... | |
Macros | |
| #define | ERROR_HEADER srn_error_t *maybe_error |
| The first member every fallible data structure embeds (see the file note above). | |
| #define | HAS_ERROR(x) |
| True when x – a value carrying an ERROR_HEADER – has an error attached. | |
| #define | ERR(ctx, err, msg) |
| #define | FAIL(ctx, T, err, msg) |
Typedefs | |
| typedef enum srn_error_tag_t | srn_error_tag_t |
| The kind of a failure. | |
| typedef struct srn_error_t | srn_error_t |
| A runtime error, a tag classifying the failure and a human-readable message. | |
Enumerations | |
| enum | srn_error_tag_t { ABSURD , SEQ_LIMIT_REACHED , INDEX_OUT_OF_BOUND , CORRUPTED_SEQ , FAILED_TO_ADD_MODULE , EMPTY_NAMESPACE_NAME , EMPTY_SYMBOL_NAME , STRING_LENGTH_LIMIT_EXCEEDED , WRONG_RANGE , EPOLL_INIT_FAILED , EPOLL_EVENT_FD_FAILED , EPOLL_FAILED_TO_ADD_FD , CONNECTION_REFUSED , CONNECTION_RESET , CONNECTION_ABORTED , BROKEN_PIPE , BAD_DESCRIPTOR , TIMED_OUT , CANCELED , NOT_CONNECTED , ADDRESS_IN_USE , HOST_UNREACHABLE , NETWORK_UNREACHABLE , MESSAGE_TOO_LONG , TOO_MANY_OPEN_FILES , PERMISSION_DENIED , OUT_OF_MEMORY , NOT_FOUND , ALREADY_EXISTS , IS_A_DIRECTORY , NOT_A_DIRECTORY , NO_SPACE , INVALID_ARGUMENT , CHANNEL_BUSY , UNKNOWN_IO_ERROR } |
| The kind of a failure. More... | |
Functions | |
| srn_error_t * | srn_errors_make (const srn_context_t *ctx, srn_error_tag_t tag, const char *msg) |
| Build an error in ctx's memory, tagged tag and carrying msg. | |
| void * | srn_errors_fail (const srn_context_t *ctx, size_t size, size_t alignment, srn_error_tag_t tag, const char *msg) |
| Allocate a size/alignment value in ctx, set its ERROR_HEADER (the first member, srn_error_t *maybe_error) to a fresh error, and return it. | |
| srn_error_tag_t | srn_errno_to_tag (int errno_value, srn_error_tag_t default_tag) |
| Map a POSIX errno to error tag. | |
Error handling for the runtime.
An srn_error_t pairs a srn_error_tag_t, naming the kind of failure, with a human-readable message, and is allocated from a srn_context_t. Fallible operations report failures as these explicit error values rather than through return codes or out-of-band state, so an error travels with the data it describes. When the Serene language layer is built, an error can also be lifted into a srn_value_t so the failure is representable inside the language itself.
By Convention, all the data structures that in anyway may, interacting with them may result in an error, must use the ERROR_HEADER macro as the first member. For example:
Following this convention let you use the error handling helpers from this header uniformly across the runtime library.
Definition in file errors.h.
| #define ERR | ( | ctx, | |
| err, | |||
| msg ) |
| #define ERROR_HEADER srn_error_t *maybe_error |
| #define FAIL | ( | ctx, | |
| T, | |||
| err, | |||
| msg ) |
| #define HAS_ERROR | ( | x | ) |
True when x – a value carrying an ERROR_HEADER – has an error attached.
Takes the struct by value, the way these results are passed and checked.
| typedef struct srn_error_t srn_error_t |
A runtime error, a tag classifying the failure and a human-readable message.
| typedef enum srn_error_tag_t srn_error_tag_t |
The kind of a failure.
Each srn_error_t carries one of these.
| enum srn_error_tag_t |
The kind of a failure.
Each srn_error_t carries one of these.
Definition at line 75 of file errors.h.
| srn_error_tag_t srn_errno_to_tag | ( | int | errno_value, |
| srn_error_tag_t | default_tag ) |
Map a POSIX errno to error tag.
Note: an errno with no mapping yields default_tag, so the caller picks the fallback that fits its domain. Defined on POSIX platforms. a non-POSIX backend should supply its own native-code mapping.
|
nodiscard |
Allocate a size/alignment value in ctx, set its ERROR_HEADER (the first member, srn_error_t *maybe_error) to a fresh error, and return it.
The result is a valid fallible value whose HAS_ERROR is true. Use the FAIL macro, which fills in size/alignment from the target type.
Definition at line 39 of file errors.c.
| srn_error_t * srn_errors_make | ( | const srn_context_t * | ctx, |
| srn_error_tag_t | tag, | ||
| const char * | msg ) |
Build an error in ctx's memory, tagged tag and carrying msg.
Returns the error to attach to a value's maybe_error (or to inspect directly). The ERR macro below is the shorthand for the common call.
Definition at line 31 of file errors.c.