Skip to content

Commit

Permalink
Add CHIP_ERROR object methods (#8784)
Browse files Browse the repository at this point in the history
* Add CHIP_ERROR object methods

#### Problem

Having CHIP_ERROR be a class type provides type safety and the option to
trace the source of errors. Since all platforms now use the class type,
transitional code that provided for CHIP_ERROR to be either a class or
integer type is no longer required and can be removed, which simplifies
the class and some notation for using errors.

#### Change overview

- Remove the `CHIP_CONFIG_ERROR_CLASS` configuration option.
- Add instance methods to replace the static `ChipError` functions, which
  were present to allow transitional integer overloads. To avoid
  breaking PRs in flight, the static methods remain present for now,
  marked “DO NOT USE”; they will be removed in a final cleanup PR.

#### Testing

Existing tests should confirm no change to functionality.

* Rebase and regen to fix ZAP/Android after #8680

* Add assertions for bit fields
  • Loading branch information
kpschoedel authored Aug 5, 2021
1 parent 203b25d commit 0fe17ec
Show file tree
Hide file tree
Showing 99 changed files with 4,412 additions and 4,586 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ std::string createSetupPayload()

if (err != CHIP_NO_ERROR)
{
ESP_LOGE(TAG, "Couldn't get payload string %" CHIP_ERROR_FORMAT, ChipError::FormatError(err));
ESP_LOGE(TAG, "Couldn't get payload string %" CHIP_ERROR_FORMAT, err.Format());
}
return result;
};
Expand Down
21 changes: 7 additions & 14 deletions examples/bridge-app/bridge-common/gen/IMClusterCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -355,8 +354,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -547,8 +545,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -1071,8 +1068,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -1752,8 +1748,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -1815,8 +1810,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -2315,8 +2309,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down
5 changes: 2 additions & 3 deletions examples/chip-tool/commands/clusters/ModelCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CHIP_ERROR ModelCommand::Run()
err = ctx->commissioner->GetConnectedDevice(ctx->remoteId, &mOnDeviceConnectedCallback, &mOnDeviceConnectionFailureCallback);
VerifyOrExit(err == CHIP_NO_ERROR,
ChipLogError(chipTool, "Failed in initiating connection to the device: %" PRIu64 ", error %" CHIP_ERROR_FORMAT,
ctx->remoteId, ChipError::FormatError(err)));
ctx->remoteId, err.Format()));

exit:
return err;
Expand All @@ -60,8 +60,7 @@ void ModelCommand::OnDeviceConnectedFn(void * context, chip::Controller::Device
void ModelCommand::OnDeviceConnectionFailureFn(void * context, NodeId deviceId, CHIP_ERROR error)
{
ModelCommand * command = reinterpret_cast<ModelCommand *>(context);
ChipLogError(chipTool, "Failed in connecting to the device %" PRIu64 ". Error %" CHIP_ERROR_FORMAT, deviceId,
ChipError::FormatError(error));
ChipLogError(chipTool, "Failed in connecting to the device %" PRIu64 ". Error %" CHIP_ERROR_FORMAT, deviceId, error.Format());
VerifyOrReturn(command != nullptr, ChipLogError(chipTool, "ModelCommand context is null"));
command->SetCommandExitStatus(error);
}
3 changes: 1 addition & 2 deletions examples/chip-tool/commands/tests/TestCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ void TestCommand::OnDeviceConnectedFn(void * context, chip::Controller::Device *

void TestCommand::OnDeviceConnectionFailureFn(void * context, NodeId deviceId, CHIP_ERROR error)
{
ChipLogError(chipTool, "Failed in connecting to the device %" PRIu64 ". Error %" CHIP_ERROR_FORMAT, deviceId,
chip::ChipError::FormatError(error));
ChipLogError(chipTool, "Failed in connecting to the device %" PRIu64 ". Error %" CHIP_ERROR_FORMAT, deviceId, error.Format());
auto * command = static_cast<TestCommand *>(context);
VerifyOrReturn(command != nullptr, ChipLogError(chipTool, "Test command context is null"));
command->SetCommandExitStatus(error);
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void appError(int err)

void appError(CHIP_ERROR error)
{
appError(static_cast<int>(chip::ChipError::AsInteger(error)));
appError(static_cast<int>(error.AsInteger()));
}

// ================================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -1696,8 +1695,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -1814,8 +1812,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -1867,8 +1864,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -2059,8 +2055,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -2583,8 +2578,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -3264,8 +3258,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -3327,8 +3320,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -3827,8 +3819,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -3880,8 +3871,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -3933,8 +3923,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down Expand Up @@ -3986,8 +3975,7 @@ void DispatchServerCommand(app::CommandHandler * apCommandObj, CommandId aComman
ChipLogProgress(Zcl,
"Failed to dispatch command, %" PRIu32 "/%" PRIu32 " arguments parsed, TLVError=%" CHIP_ERROR_FORMAT
", UnpackError=%" CHIP_ERROR_FORMAT " (last decoded tag = %" PRIu32,
validArgumentCount, expectArgumentCount, ChipError::FormatError(TLVError),
ChipError::FormatError(TLVUnpackError), currentDecodeTagId);
validArgumentCount, expectArgumentCount, TLVError.Format(), TLVUnpackError.Format(), currentDecodeTagId);
// A command with no arguments would never write currentDecodeTagId. If
// progress logging is also disabled, it would look unused. Silence that
// warning.
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/nrfconnect/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ int main(void)
}

exit:
LOG_ERR("Exited with code %" CHIP_ERROR_FORMAT, chip::ChipError::FormatError(err));
LOG_ERR("Exited with code %" CHIP_ERROR_FORMAT, err.Format());
return err == CHIP_NO_ERROR ? EXIT_SUCCESS : EXIT_FAILURE;
}
2 changes: 1 addition & 1 deletion examples/lighting-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void AppTask::AppTaskMain(void * pvParameter)
CHIP_ERROR err = sAppTask.Init();
if (err != CHIP_NO_ERROR)
{
ChipLogError(NotSpecified, "AppTask.Init() failed: %" CHIP_ERROR_FORMAT, chip::ChipError::FormatError(err));
ChipLogError(NotSpecified, "AppTask.Init() failed: %" CHIP_ERROR_FORMAT, err.Format());
// appError(err);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void appError(int err)

void appError(CHIP_ERROR error)
{
appError(static_cast<int>(chip::ChipError::AsInteger(error)));
appError(static_cast<int>(error.AsInteger()));
}

// ================================================================================
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/esp32/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void AppTask::AppTaskMain(void * pvParameter)
CHIP_ERROR err = sAppTask.Init();
if (err != CHIP_NO_ERROR)
{
ESP_LOGI(TAG, "AppTask.Init() failed due to %" CHIP_ERROR_FORMAT, chip::ChipError::FormatError(err));
ESP_LOGI(TAG, "AppTask.Init() failed due to %" CHIP_ERROR_FORMAT, err.Format());
return;
}

Expand Down
Loading

0 comments on commit 0fe17ec

Please sign in to comment.