Skip to content

Commit

Permalink
Merge pull request OpenAssetIO#1387 from feltech/work/1060-batchEleme…
Browse files Browse the repository at this point in the history
…ntCodeEnumNotMacro

Use enum for BatchElementError codes
  • Loading branch information
feltech authored Aug 7, 2024
2 parents c783718 + 7d368f3 commit a6e9cf3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 68 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ section for more details._
`reserve(...)`).
[#1339](https://github.com/OpenAssetIO/OpenAssetIO/issues/1339)

- Source values for `BatchElementError` error codes changed to an
internally-namespaced `enum` rather than global macros.
[#1060](https://github.com/OpenAssetIO/OpenAssetIO/issues/1060)

### New Features

- Added SimpleCppManager - a minimal C++ manager and plugin example
Expand Down
4 changes: 1 addition & 3 deletions src/openassetio-core-c/include/openassetio/c/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Copyright 2013-2022 The Foundry Visionmongers Ltd
#pragma once

#include <openassetio/errors/errorCodes.h>

#include "./namespace.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -43,7 +41,7 @@ typedef enum {
/// Error code indicating an OK result from a C API function.
oa_ErrorCode_kOK = 0,
/// Error code representing a generic non-exception type thrown.
oa_ErrorCode_kUnknown = OPENASSETIO_ErrorCode_BEGIN,
oa_ErrorCode_kUnknown,
/// Error code representing a generic C++ exception.
oa_ErrorCode_kException,
/// Error code representing a C++ std::bad_variant_access exception.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
// Copyright 2022 The Foundry Visionmongers Ltd
#pragma once

#include <functional>
#include <stdexcept>
#include <string>
#include <utility>
#include <type_traits>

#include <openassetio/errors/errorCodes.h>
#include <openassetio/export.h>
#include <openassetio/internal.hpp>
#include <openassetio/typedefs.hpp>

namespace openassetio {
Expand Down Expand Up @@ -51,7 +48,7 @@ class BatchElementError final {
/// Possible classes of error.
enum class ErrorCode {
/// Fallback for uncommon errors.
kUnknown = OPENASSETIO_BatchErrorCode_kUnknown,
kUnknown = internal::errors::kBatchElementUnknownError,

/**
* Error code used whenever an entity reference is not one that
Expand All @@ -60,7 +57,7 @@ class BatchElementError final {
* In the case of a manager that uses standard URIs, then it
* could be that the scheme is that of another manager.
*/
kInvalidEntityReference = OPENASSETIO_BatchErrorCode_kInvalidEntityReference,
kInvalidEntityReference = internal::errors::kBatchElementInvalidEntityReference,

/**
* Error code used whenever an entity-based action is performed on
Expand All @@ -79,7 +76,7 @@ class BatchElementError final {
* parameters is missing for a given operation, or a supplied
* parameter is not relevant to that particular operation/entity.
*/
kMalformedEntityReference = OPENASSETIO_BatchErrorCode_kMalformedEntityReference,
kMalformedEntityReference = internal::errors::kBatchElementMalformedEntityReference,

/**
* Error code used when the reference is valid, but the supplied
Expand All @@ -89,7 +86,7 @@ class BatchElementError final {
* glossary_register when the target entity s read-only and does not
* support updating.
*/
kEntityAccessError = OPENASSETIO_BatchErrorCode_kEntityAccessError,
kEntityAccessError = internal::errors::kBatchElementEntityAccessError,

/**
* Error code used during @ref glossary_resolve "entity resolution"
Expand All @@ -108,7 +105,7 @@ class BatchElementError final {
* entity-based operations on a valid @ref entity_reference that
* fail for some reason.
*/
kEntityResolutionError = OPENASSETIO_BatchErrorCode_kEntityResolutionError,
kEntityResolutionError = internal::errors::kBatchElementEntityResolutionError,

/**
* Error code response from @ref glossary_preflight if the provided
Expand All @@ -119,13 +116,13 @@ class BatchElementError final {
* host owns to be passed to `preflight`, but the host did not
* provide it.
*/
kInvalidPreflightHint = OPENASSETIO_BatchErrorCode_kInvalidPreflightHint,
kInvalidPreflightHint = internal::errors::kBatchElementInvalidPreflightHint,

/**
* Error code used whenever a trait set is not one that is known to
* the manager.
*/
kInvalidTraitSet = OPENASSETIO_BatchErrorCode_kInvalidTraitSet,
kInvalidTraitSet = internal::errors::kBatchElementInvalidTraitSet,

/**
* Error code indicating that the host is not authorized for a
Expand All @@ -139,7 +136,7 @@ class BatchElementError final {
* action, or a particular entity. The error message should provide
* details of the reason.
*/
kAuthError = OPENASSETIO_BatchErrorCode_kAuthError,
kAuthError = internal::errors::kBatchElementAuthError,
};

/**
Expand Down
52 changes: 0 additions & 52 deletions src/openassetio-core/include/openassetio/errors/errorCodes.h

This file was deleted.

19 changes: 19 additions & 0 deletions src/openassetio-core/include/openassetio/internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ namespace access {
enum Access : std::size_t { kRead = 0, kWrite, kCreateRelated, kRequired, kManagerDriven };
} // namespace access

namespace errors {
/**
* Common constant values for error codes.
*
* The enum values must be kept in sync with the C API.
*/
enum ErrorCode : std::size_t {
// 0-127 is reserved for C API error codes.
kBatchElementUnknownError = 128,
kBatchElementInvalidEntityReference,
kBatchElementMalformedEntityReference,
kBatchElementEntityAccessError,
kBatchElementEntityResolutionError,
kBatchElementInvalidPreflightHint,
kBatchElementInvalidTraitSet,
kBatchElementAuthError
};
} // namespace errors

namespace capability::manager {
/**
* Common constant values for strong enumerations of capability sets.
Expand Down

0 comments on commit a6e9cf3

Please sign in to comment.