libropkg: add error message definitions

This commit is contained in:
2025-07-21 22:43:32 +01:00
parent 10603ed2d1
commit 2480e9950c
2 changed files with 150 additions and 0 deletions

View File

@@ -1,6 +1,15 @@
#ifndef ROPKG_STATUS_H_ #ifndef ROPKG_STATUS_H_
#define ROPKG_STATUS_H_ #define ROPKG_STATUS_H_
#include <blue/core/error.h>
#include <ropkg/misc.h>
#define ROPKG_ERROR_VENDOR (ropkg_error_vendor())
#define ROPKG_RESULT_ERR(code) \
b_error_with_code(ROPKG_ERROR_VENDOR, ROPKG_ERR_##code)
#define ROPKG_RESULT_SUCCESS B_RESULT_SUCCESS
enum ropkg_status { enum ropkg_status {
ROPKG_SUCCESS = 0, ROPKG_SUCCESS = 0,
ROPKG_ERR_NOT_SUPPORTED, ROPKG_ERR_NOT_SUPPORTED,
@@ -9,6 +18,34 @@ enum ropkg_status {
ROPKG_ERR_BAD_STATE, ROPKG_ERR_BAD_STATE,
ROPKG_ERR_INTERNAL_FAILURE, ROPKG_ERR_INTERNAL_FAILURE,
ROPKG_ERR_IO_FAILURE, ROPKG_ERR_IO_FAILURE,
ROPKG_ERR_DIR_OPEN_FAILED,
ROPKG_ERR_INSTANCE_DIR_CREATE_FAILED,
ROPKG_ERR_FILE_OPEN_FAILED,
ROPKG_ERR_INVALID_VERSION_FORMAT,
}; };
enum ropkg_error_msg {
ROPKG_EMSG_SUCCESS = 0,
ROPKG_EMSG_AVAILABLE_RELEASE_PHASES,
ROPKG_EMSG_AVAILABLE_VERSION_RELEASE_PHASES,
ROPKG_EMSG_INVALID_UPSTREAM_VERSION_UNKNOWN_START,
ROPKG_EMSG_INVALID_UPSTREAM_VERSION_TWO_DOTS,
ROPKG_EMSG_INVALID_UPSTREAM_VERSION_END_DOT,
ROPKG_EMSG_INVALID_UPSTREAM_VERSION_TOO_MANY_NUMBERS,
ROPKG_EMSG_INVALID_RELEASE_PHASE,
ROPKG_EMSG_INVALID_VERSION_RELEASE_PHASE,
ROPKG_EMSG_INVALID_VERSION_RELEASE_PHASE_UNKNOWN_START,
ROPKG_EMSG_INVALID_PACKAGE_REVISION_UNKNOWN_START,
ROPKG_EMSG_INVALID_VERSION_UNKNOWN_END,
};
ROPKG_API const struct b_error_vendor *ropkg_error_vendor(void);
#endif #endif

View File

@@ -0,0 +1,113 @@
#include <blue/core/error.h>
#include <ropkg/status.h>
static const b_error_definition ropkg_errors[] = {
B_ERROR_DEFINITION(ROPKG_SUCCESS, "SUCCESS", "Success"),
B_ERROR_DEFINITION(
ROPKG_ERR_NOT_SUPPORTED,
"NOT_SUPPORTED",
"Operation not supported"),
B_ERROR_DEFINITION(
ROPKG_ERR_INVALID_ARGUMENT,
"INVALID_ARGUMENT",
"Invalid argument"),
B_ERROR_DEFINITION(ROPKG_ERR_NO_MEMORY, "NO_MEMORY", "Out of memory"),
B_ERROR_DEFINITION(ROPKG_ERR_BAD_STATE, "BAD_STATE", "Bad state"),
B_ERROR_DEFINITION(
ROPKG_ERR_INTERNAL_FAILURE,
"INTERNAL_FAILURE",
"Internal failure"),
B_ERROR_DEFINITION(ROPKG_ERR_IO_FAILURE, "IO_FAILURE", "I/O failure"),
B_ERROR_DEFINITION_TEMPLATE(
ROPKG_ERR_DIR_OPEN_FAILED,
"DIR_OPEN_FAILED",
"Cannot open directory @i[filepath]",
B_ERROR_TEMPLATE_PARAM(
"filepath",
B_ERROR_TEMPLATE_PARAM_STRING,
"%s")),
B_ERROR_DEFINITION_TEMPLATE(
ROPKG_ERR_INSTANCE_DIR_CREATE_FAILED,
"INSTANCE_DIR_CREATE_FAILED",
"Cannot create sub-directory @i[subdirpath] in instance "
"@i[instancepath]",
B_ERROR_TEMPLATE_PARAM(
"instancepath",
B_ERROR_TEMPLATE_PARAM_STRING,
"%s"),
B_ERROR_TEMPLATE_PARAM(
"subdirpath",
B_ERROR_TEMPLATE_PARAM_STRING,
"%s")),
B_ERROR_DEFINITION_TEMPLATE(
ROPKG_ERR_FILE_OPEN_FAILED,
"FILE_OPEN_FAILED",
"Cannot open file @i[filepath]",
B_ERROR_TEMPLATE_PARAM(
"filepath",
B_ERROR_TEMPLATE_PARAM_STRING,
"%s")),
B_ERROR_DEFINITION(
ROPKG_ERR_INVALID_VERSION_FORMAT,
"INVALID_VERSION_FORMAT",
"Invalid version format"),
};
static const b_error_msg ropkg_error_msg[] = {
B_ERROR_MSG_TEMPLATE(
ROPKG_EMSG_INVALID_RELEASE_PHASE,
"@i[phase] is not a valid package release phase",
B_ERROR_TEMPLATE_PARAM(
"phase",
B_ERROR_TEMPLATE_PARAM_STRING,
"%s")),
B_ERROR_MSG(
ROPKG_EMSG_AVAILABLE_RELEASE_PHASES,
"valid release phases: @i{alpha}, @i{beta}"),
B_ERROR_MSG(
ROPKG_EMSG_AVAILABLE_VERSION_RELEASE_PHASES,
"valid version release phases: @i{alpha}, @i{beta}, @i{rc}"),
B_ERROR_MSG(
ROPKG_EMSG_INVALID_UPSTREAM_VERSION_UNKNOWN_START,
"unexpected character found while parsing upstream version"),
B_ERROR_MSG(
ROPKG_EMSG_INVALID_UPSTREAM_VERSION_TWO_DOTS,
"two consecutive full stops found in upstream version"),
B_ERROR_MSG(
ROPKG_EMSG_INVALID_UPSTREAM_VERSION_END_DOT,
"upstream version identifier cannot end with a full stop"),
B_ERROR_MSG(
ROPKG_EMSG_INVALID_UPSTREAM_VERSION_TOO_MANY_NUMBERS,
"upstream version can contain no more than five number "
"components"),
B_ERROR_MSG_TEMPLATE(
ROPKG_EMSG_INVALID_VERSION_RELEASE_PHASE,
"@i[phase] is not a valid package version release phase",
B_ERROR_TEMPLATE_PARAM(
"phase",
B_ERROR_TEMPLATE_PARAM_STRING,
"%s")),
B_ERROR_MSG(
ROPKG_EMSG_INVALID_VERSION_UNKNOWN_END,
"unrecognised characters at the end of the version identifier"),
};
static const b_error_vendor ropkg_error_vend = {
.v_name = "Ropkg",
.v_error_definitions = ropkg_errors,
.v_error_definitions_length = sizeof ropkg_errors,
.v_msg = ropkg_error_msg,
.v_msg_length = sizeof ropkg_error_msg,
};
const struct b_error_vendor *ropkg_error_vendor(void)
{
return &ropkg_error_vend;
}