-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a SDK part of IM Cluster Status Success
to CHIP_ERROR
#34597
Add a SDK part of IM Cluster Status Success
to CHIP_ERROR
#34597
Conversation
Review changes with SemanticDiff. |
PR #34597: Size comparison from 37fc757 to 5695fa4 Increases above 0.2%:
Full report (85 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, mbed, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
kIMGlobalStatus = 5, ///< Interaction Model global status code. | ||
kIMClusterStatusFailure = 6, ///< Interaction Model cluster-specific status code (failure) | ||
kApplication = 7, ///< Application-defined errors; see CHIP_APPLICATION_ERROR | ||
kIMClusterStatusSuccess = 8, ///< Interaction Model cluster-specific status code (success) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We sort of purposefully did not do this, because encoding a "success" status as a CHIP_ERROR is really weird and brittle: various callers have to know that your error is not really an error and that things should be propagated properly.
This is particularly bad when the thing returning this is not in tail-call position, obviously.
For cases when we might have a cluster-specific success we really need to be using a different return type than CHIP_ERROR, or use CHIP_ERROR to indicate actualy errors but have an out-param for the status or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difficulty was that conceptually Read/Write/Invoke are supposed to be StatusIB (so ClusterStatus) however for chunking we are also expecting a CHIP_ERROR to encode the out of space errors.
I am concerned that the ripple effect of that. The existing code logic is not very clean on single-return because AddStatus
is separated from error code return
and that allowed our types to diverge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing we could do:
- Add an
mOutOfSpace
member toAttributeValueEncoder
. - Set this member as needed in the relevant public
Encode
methods (we can do this without too much codesize hit, maybe). - Have whatever created the AttributeValueEncoder check that state (like it already checks the
mTriedEncode
state) and handle it appropriately. - Change
AttributeAccessInterface::Read
to returnClusterStatus
- Change
DataModel::Provider::ReadAttribute
to returnClusterStatus
That does mean not being able to use ReturnErrorOnFailure() all over in Read
, though....
Another option is to just hang the ClusterStatus off the AttributeValueEncoder and the few consumers that want a success status can do that, and we check for it in the one chokepoint at the callsite.
closing for #34708 |
CHIP_ERROR currently covers global IM statuses as well as cluster-specific failures, however we did not cover cluster specific successes.
This PR adds a new part to CHIP_ERROR that encodes cluster statuses and updates StatusIB to be able to convert from them. Note that this still considers such
success
statuses as a CHIP_ERROR since the overhead of converting all tests to not check CHIP_NO_ERROR and have code inside IsSuccess would be quite expensive.Background of this change:
Working on DataModel interface split, where Writes may return a CHIP_ERROR currently however that fails to encode ClusterSuccess.
I also considered making the DM provider interfaces return
ClusterStatus
however that requires more work since ReadAttribute relies on non-status errors like CHIP_NO_MEMORY to control code paths. As such, having a better return (e.g. astd::variant<ClusterStatus, ProcessingError>
where ProcessingError would be out of space) requires more thought. Also a lot of SDK code returns CHIP_ERROR, so a CHIP_ERROR based interface seems slightly more convenient to use at this point).