Skip to content

Commit

Permalink
Allow Darwin framework errors to represend all IM errors. (#14973)
Browse files Browse the repository at this point in the history
We kept having to add IM errors one at a time.  Just add them all at
once.

Also more clearly disambiguates "IM error status returned" from
"something went wrong on our end".
  • Loading branch information
bzbarsky-apple authored Feb 10, 2022
1 parent 56634bf commit 87d1d3e
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 285 deletions.
3 changes: 2 additions & 1 deletion src/app/data-model/Decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <lib/core/CHIPSafeCasts.h>
#include <lib/core/CHIPTLV.h>
#include <lib/core/Optional.h>
#include <protocols/interaction_model/Constants.h>

namespace chip {
namespace app {
Expand Down Expand Up @@ -161,7 +162,7 @@ CHIP_ERROR Decode(TLV::TLVReader & reader, Nullable<X> & x)
ReturnErrorOnFailure(Decode(reader, x.SetNonNull()));
if (!x.HasValidValue())
{
return CHIP_ERROR_IM_CONSTRAINT_ERROR;
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
}
return CHIP_NO_ERROR;
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/data-model/Encode.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <app/data-model/Nullable.h>
#include <lib/core/CHIPTLV.h>
#include <lib/core/Optional.h>
#include <protocols/interaction_model/Constants.h>

#include <type_traits>

Expand Down Expand Up @@ -123,7 +124,7 @@ CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag, const Nullable<X> & x)
#if !CONFIG_IM_BUILD_FOR_UNIT_TEST
if (!x.HasValidValue())
{
return CHIP_ERROR_IM_CONSTRAINT_ERROR;
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
}
#endif // !CONFIG_IM_BUILD_FOR_UNIT_TEST
return Encode(writer, tag, x.Value());
Expand Down
6 changes: 3 additions & 3 deletions src/darwin/Framework/CHIP/CHIPDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void OnAttributeData(
void OnSubscriptionEstablished(uint64_t aSubscriptionId) override;

void ReportError(CHIP_ERROR err);
void ReportError(EmberAfStatus status);
void ReportError(const StatusIB & status);
void ReportError(NSError * _Nullable err);

private:
Expand Down Expand Up @@ -223,7 +223,7 @@ - (instancetype)initWithPath:(const ConcreteDataAttributePath &)path value:(null
}

if (aStatus.mStatus != Status::Success) {
ReportError(ToEmberAfStatus(aStatus.mStatus));
ReportError(aStatus);
return;
}

Expand Down Expand Up @@ -274,7 +274,7 @@ - (instancetype)initWithPath:(const ConcreteDataAttributePath &)path value:(null

void SubscriptionCallback::ReportError(CHIP_ERROR err) { ReportError([CHIPError errorForCHIPErrorCode:err]); }

void SubscriptionCallback::ReportError(EmberAfStatus status) { ReportError([CHIPError errorForZCLErrorCode:status]); }
void SubscriptionCallback::ReportError(const StatusIB & status) { ReportError([CHIPError errorForIMStatus:status]); }

void SubscriptionCallback::ReportError(NSError * _Nullable err)
{
Expand Down
79 changes: 68 additions & 11 deletions src/darwin/Framework/CHIP/CHIPError.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,83 @@
NS_ASSUME_NONNULL_BEGIN
FOUNDATION_EXPORT NSErrorDomain const CHIPErrorDomain;

FOUNDATION_EXPORT NSErrorDomain const MatterInteractionErrorDomain;

/**
* ChipErrorDomain contains errors caused by data processing the framework
* itself is performing. These can be caused by invalid values provided to a
* framework API, failure to decode an incoming message, and so forth.
*
* Errors reported by the other side of a Matter interaction use
* MatterInteractionErrorDomain instead.
*/
// clang-format off
typedef NS_ERROR_ENUM(CHIPErrorDomain, CHIPErrorCode){
CHIPErrorCodeUndefinedError = 1,
/**
* CHIPErrorCodeGeneralError represents a generic Matter error with no
* further categorization.
*
* The userInfo will have a key named @"errorCode" whose value will be an
* integer representing the underlying Matter error code. These integer
* values should not be assumed to be stable across releases, but may be
* useful in logging and debugging.
*/
CHIPErrorCodeGeneralError = 1,
CHIPErrorCodeInvalidStringLength = 2,
CHIPErrorCodeInvalidIntegerValue = 3,
CHIPErrorCodeInvalidArgument = 4,
CHIPErrorCodeInvalidMessageLength = 5,
CHIPErrorCodeInvalidState = 6,
CHIPErrorCodeWrongAddressType = 7,
CHIPErrorCodeIntegrityCheckFailed = 8,
CHIPErrorCodeDuplicateExists = 9,
CHIPErrorCodeUnsupportedEndpoint = 0x7F,
CHIPErrorCodeUnsupportedCommand = 0x81,
CHIPErrorCodeInvalidCommand = 0x85,
CHIPErrorCodeUnsupportedAttribute = 0x86,
CHIPErrorCodeConstraintError = 0x87,
CHIPErrorCodeUnsupportedWrite = 0x88,
CHIPErrorCodeNotFound = 0x8B,
CHIPErrorCodeInvalidDataType = 0x8D,
CHIPErrorCodeUnsupportedCluster = 0xC3,
};
// clang-format on

/**
* MatterInteractionErrorDomain contains errors that represent a Matter
* StatusIB error. These represent errors reported by the other side of a
* Matter interaction.
*
* When the code is MatterInteractionErrorCodeFailure the userInfo may have a
* key named @"clusterStatus" whose value is the cluster-specific status that
* was reported. This key will be absent if there was no cluster-specific
* status.
*/
// clang-format off
typedef NS_ERROR_ENUM(MatterInteractionErrorDomain, MatterInteractionErrorCode){
// These values come from the general status code table in the Matter
// Interaction Model specification. Do not change these values unless the
// specification changes.
MatterInteractionErrorCodeFailure = 0x01,
MatterInteractionErrorCodeInvalidSubscription = 0x7d,
MatterInteractionErrorCodeUnsupportedAccess = 0x7e,
MatterInteractionErrorCodeUnsupportedEndpoint = 0x7f,
MatterInteractionErrorCodeInvalidAction = 0x80,
MatterInteractionErrorCodeUnsupportedCommand = 0x81,
// Gap in values is intentional.
MatterInteractionErrorCodeInvalidCommand = 0x85,
MatterInteractionErrorCodeUnsupportedAttribute = 0x86,
MatterInteractionErrorCodeConstraintError = 0x87,
MatterInteractionErrorCodeUnsupportedWrite = 0x88,
MatterInteractionErrorCodeResourceExhausted = 0x89,
// Gap in values is intentional.
MatterInteractionErrorCodeNotFound = 0x8b,
MatterInteractionErrorCodeUnreportableAttribute = 0x8c,
MatterInteractionErrorCodeInvalidDataType = 0x8d,
// Gap in values is intentional.
MatterInteractionErrorCodeUnsupportedRead = 0x8f,
// Gap in values is intentional.
MatterInteractionErrorCodeDataVersionMismatch = 0x92,
// Gap in values is intentional.
MatterInteractionErrorCodeTimeout = 0x94,
// Gap in values is intentional.
MatterInteractionErrorCodeBusy = 0x9c,
// Gap in values is intentional.
MatterInteractionErrorCodeUnsupportedCluster = 0xc3,
// Gap in values is intentional.
MatterInteractionErrorCodeNoUpstreamSubscription = 0xc5,
MatterInteractionErrorCodeNeedsTimedInteraction = 0xc6,
MatterInteractionErrorCodeUnsupportedEvent = 0xc7,
};
// clang-format on

Expand Down
Loading

0 comments on commit 87d1d3e

Please sign in to comment.