Split Die/Exit/Return macros out of CodeUtils.h (#5578)
#### Problem
Requested followup from #5545
#### Summary of Changes
- Move ‘Die’ macros to `<support/DieMacros.h>`
- Move ‘Error’ macros to `<support/ErrorMacros.h>`
- Move ‘Return’ macros to `<support/ReturnMacros.h>`
- Fix `#include`s for former `CodeUtils.h` contents.
diff --git a/examples/all-clusters-app/esp32/main/Button.cpp b/examples/all-clusters-app/esp32/main/Button.cpp
index 352428e..d19772f 100644
--- a/examples/all-clusters-app/esp32/main/Button.cpp
+++ b/examples/all-clusters-app/esp32/main/Button.cpp
@@ -30,7 +30,7 @@
#include "Button.h"
#include <platform/CHIPDeviceLayer.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
extern const char * TAG;
diff --git a/examples/all-clusters-app/esp32/main/CHIPDeviceManager.cpp b/examples/all-clusters-app/esp32/main/CHIPDeviceManager.cpp
index f7c5570..d1334b4 100644
--- a/examples/all-clusters-app/esp32/main/CHIPDeviceManager.cpp
+++ b/examples/all-clusters-app/esp32/main/CHIPDeviceManager.cpp
@@ -28,7 +28,7 @@
#include <app/util/basic-types.h>
#include <setup_payload/SetupPayload.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
using namespace ::chip;
diff --git a/examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp b/examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp
index 2ed3246..ca643bb 100644
--- a/examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp
+++ b/examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp
@@ -36,7 +36,7 @@
#include <app/util/basic-types.h>
#include <app/util/util.h>
#include <lib/mdns/Advertiser.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
static const char * TAG = "app-devicecallbacks";
diff --git a/examples/all-clusters-app/esp32/main/QRCodeScreen.cpp b/examples/all-clusters-app/esp32/main/QRCodeScreen.cpp
index f43e798..5d47dec 100644
--- a/examples/all-clusters-app/esp32/main/QRCodeScreen.cpp
+++ b/examples/all-clusters-app/esp32/main/QRCodeScreen.cpp
@@ -40,7 +40,6 @@
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
-#include <support/CodeUtils.h>
// TODO need sensible library tag when put in library
extern const char * TAG;
diff --git a/examples/all-clusters-app/linux/main.cpp b/examples/all-clusters-app/linux/main.cpp
index 18a90d1..e1f9ab5 100644
--- a/examples/all-clusters-app/linux/main.cpp
+++ b/examples/all-clusters-app/linux/main.cpp
@@ -28,6 +28,8 @@
#include <app/util/util.h>
#include <core/CHIPError.h>
#include <support/CHIPMem.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
#include <support/RandUtils.h>
#include "Server.h"
diff --git a/examples/bridge-app/linux/main.cpp b/examples/bridge-app/linux/main.cpp
index bc721b0..f02699b 100644
--- a/examples/bridge-app/linux/main.cpp
+++ b/examples/bridge-app/linux/main.cpp
@@ -30,6 +30,8 @@
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>
#include <support/CHIPMem.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
#include <support/RandUtils.h>
#include "LightingManager.h"
diff --git a/examples/chip-tool/commands/clusters/ModelCommand.cpp b/examples/chip-tool/commands/clusters/ModelCommand.cpp
index d71c5d2..abebf1a 100644
--- a/examples/chip-tool/commands/clusters/ModelCommand.cpp
+++ b/examples/chip-tool/commands/clusters/ModelCommand.cpp
@@ -18,6 +18,9 @@
#include "ModelCommand.h"
+#include <core/CHIPError.h>
+#include <support/ErrorStr.h>
+
#include <inttypes.h>
using namespace ::chip;
diff --git a/examples/chip-tool/commands/common/Command.cpp b/examples/chip-tool/commands/common/Command.cpp
index f7eadcc..c87584e 100644
--- a/examples/chip-tool/commands/common/Command.cpp
+++ b/examples/chip-tool/commands/common/Command.cpp
@@ -23,6 +23,7 @@
#include <sys/socket.h>
#include <sys/types.h>
+#include <support/ErrorMacros.h>
#include <support/SafeInt.h>
#include <support/logging/CHIPLogging.h>
diff --git a/examples/chip-tool/commands/common/Command.h b/examples/chip-tool/commands/common/Command.h
index db847b9..4eafb3d 100644
--- a/examples/chip-tool/commands/common/Command.h
+++ b/examples/chip-tool/commands/common/Command.h
@@ -20,7 +20,9 @@
#include <app/server/DataModelHandler.h>
#include <controller/CHIPDeviceController.h>
+#include <core/CHIPError.h>
#include <inet/InetInterface.h>
+#include <support/ErrorStr.h>
#include <support/logging/CHIPLogging.h>
#include <atomic>
diff --git a/examples/chip-tool/commands/common/Commands.cpp b/examples/chip-tool/commands/common/Commands.cpp
index 604ded8..05eefac 100644
--- a/examples/chip-tool/commands/common/Commands.cpp
+++ b/examples/chip-tool/commands/common/Commands.cpp
@@ -28,7 +28,8 @@
#endif
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
void Commands::Register(const char * clusterName, commands_list commandsList)
{
diff --git a/examples/lighting-app/linux/main.cpp b/examples/lighting-app/linux/main.cpp
index 940a204..27088b2 100644
--- a/examples/lighting-app/linux/main.cpp
+++ b/examples/lighting-app/linux/main.cpp
@@ -30,6 +30,8 @@
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>
#include <support/CHIPMem.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
#include <support/RandUtils.h>
#include "LightingManager.h"
diff --git a/examples/lighting-app/nrfconnect/main/AppTask.cpp b/examples/lighting-app/nrfconnect/main/AppTask.cpp
index 871d410..3292a05 100644
--- a/examples/lighting-app/nrfconnect/main/AppTask.cpp
+++ b/examples/lighting-app/nrfconnect/main/AppTask.cpp
@@ -40,6 +40,7 @@
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
#include <system/SystemClock.h>
diff --git a/examples/lock-app/qpg6100/src/AppTask.cpp b/examples/lock-app/qpg6100/src/AppTask.cpp
index e51a9a2..bf5baa0 100644
--- a/examples/lock-app/qpg6100/src/AppTask.cpp
+++ b/examples/lock-app/qpg6100/src/AppTask.cpp
@@ -39,7 +39,9 @@
using namespace chip::TLV;
using namespace chip::DeviceLayer;
+#include <core/CHIPError.h>
#include <platform/CHIPDeviceLayer.h>
+#include <support/ErrorStr.h>
#if CHIP_ENABLE_OPENTHREAD
#include <platform/OpenThread/OpenThreadUtils.h>
#include <platform/ThreadStackManager.h>
diff --git a/examples/lock-app/qpg6100/src/BoltLockManager.cpp b/examples/lock-app/qpg6100/src/BoltLockManager.cpp
index 888355b..8049b40 100644
--- a/examples/lock-app/qpg6100/src/BoltLockManager.cpp
+++ b/examples/lock-app/qpg6100/src/BoltLockManager.cpp
@@ -22,6 +22,7 @@
#include "AppConfig.h"
#include "AppTask.h"
#include <FreeRTOS.h>
+#include <support/logging/CHIPLogging.h>
BoltLockManager BoltLockManager::sLock;
diff --git a/examples/persistent-storage/KeyValueStorageTest.cpp b/examples/persistent-storage/KeyValueStorageTest.cpp
index a3369f1..2f217b9 100644
--- a/examples/persistent-storage/KeyValueStorageTest.cpp
+++ b/examples/persistent-storage/KeyValueStorageTest.cpp
@@ -23,6 +23,7 @@
#include <platform/KeyValueStoreManager.h>
#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
using namespace chip::DeviceLayer::PersistedStorage;
diff --git a/examples/persistent-storage/linux/main.cpp b/examples/persistent-storage/linux/main.cpp
index f2760ff..e9487d2 100644
--- a/examples/persistent-storage/linux/main.cpp
+++ b/examples/persistent-storage/linux/main.cpp
@@ -20,6 +20,7 @@
#include <core/CHIPError.h>
#include <support/CHIPMem.h>
+#include <support/ErrorMacros.h>
#include "KeyValueStorageTest.h"
#include <platform/KeyValueStoreManager.h>
diff --git a/examples/platform/efr32/Service.cpp b/examples/platform/efr32/Service.cpp
index e810c1b..718bb18 100644
--- a/examples/platform/efr32/Service.cpp
+++ b/examples/platform/efr32/Service.cpp
@@ -32,7 +32,6 @@
#include <inet/InetError.h>
#include <inet/InetLayer.h>
#include <platform/CHIPDeviceLayer.h>
-#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
#include <system/SystemPacketBuffer.h>
#include <transport/SecureSessionMgr.h>
diff --git a/examples/platform/qpg6100/app/Service.cpp b/examples/platform/qpg6100/app/Service.cpp
index 39b190d..5c2aeb0 100644
--- a/examples/platform/qpg6100/app/Service.cpp
+++ b/examples/platform/qpg6100/app/Service.cpp
@@ -37,7 +37,6 @@
#include <inet/InetError.h>
#include <inet/InetLayer.h>
#include <platform/CHIPDeviceLayer.h>
-#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
#include <system/SystemPacketBuffer.h>
#include <transport/SecureSessionMgr.h>
diff --git a/examples/shell/shell_common/cmd_base64.cpp b/examples/shell/shell_common/cmd_base64.cpp
index f9dd84a..ce5dcd0 100644
--- a/examples/shell/shell_common/cmd_base64.cpp
+++ b/examples/shell/shell_common/cmd_base64.cpp
@@ -21,7 +21,9 @@
#include <lib/support/Base64.h>
#include <lib/support/CHIPArgParser.hpp>
#include <lib/support/CodeUtils.h>
+#include <lib/support/ErrorMacros.h>
#include <lib/support/RandUtils.h>
+#include <lib/support/logging/CHIPLogging.h>
#include <inttypes.h>
#include <stdarg.h>
diff --git a/examples/shell/shell_common/cmd_btp.cpp b/examples/shell/shell_common/cmd_btp.cpp
index 46789cf..f72832d 100644
--- a/examples/shell/shell_common/cmd_btp.cpp
+++ b/examples/shell/shell_common/cmd_btp.cpp
@@ -29,6 +29,7 @@
#include <support/CHIPArgParser.hpp>
#include <support/CHIPMem.h>
#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
using namespace chip;
using namespace chip::Shell;
diff --git a/examples/shell/shell_common/cmd_device.cpp b/examples/shell/shell_common/cmd_device.cpp
index ac079f2..e16e22a 100644
--- a/examples/shell/shell_common/cmd_device.cpp
+++ b/examples/shell/shell_common/cmd_device.cpp
@@ -25,6 +25,8 @@
#include <lib/support/CHIPArgParser.hpp>
#include <lib/support/CHIPMem.h>
#include <lib/support/CodeUtils.h>
+#include <lib/support/ErrorMacros.h>
+#include <lib/support/ErrorStr.h>
#include <platform/CHIPDeviceLayer.h>
#if CHIP_ENABLE_OPENTHREAD
#include <platform/ThreadStackManager.h>
diff --git a/examples/shell/shell_common/cmd_misc.cpp b/examples/shell/shell_common/cmd_misc.cpp
index dfd90ff..bdca1ac 100644
--- a/examples/shell/shell_common/cmd_misc.cpp
+++ b/examples/shell/shell_common/cmd_misc.cpp
@@ -22,6 +22,7 @@
#include <lib/support/CHIPArgParser.hpp>
#include <lib/support/CodeUtils.h>
#include <lib/support/RandUtils.h>
+#include <lib/support/logging/CHIPLogging.h>
#include <inttypes.h>
#include <stdarg.h>
diff --git a/examples/shell/shell_common/cmd_otcli.cpp b/examples/shell/shell_common/cmd_otcli.cpp
index 1af77c1..81a5913 100644
--- a/examples/shell/shell_common/cmd_otcli.cpp
+++ b/examples/shell/shell_common/cmd_otcli.cpp
@@ -30,7 +30,7 @@
#include <lib/shell/shell.h>
#include <lib/support/CHIPArgParser.hpp>
#include <lib/support/CHIPMem.h>
-#include <lib/support/CodeUtils.h>
+#include <lib/support/ErrorMacros.h>
#include <platform/ThreadStackManager.h>
#if CHIP_TARGET_STYLE_EMBEDDED
diff --git a/examples/shell/shell_common/cmd_ping.cpp b/examples/shell/shell_common/cmd_ping.cpp
index 9a61432..1c40342 100644
--- a/examples/shell/shell_common/cmd_ping.cpp
+++ b/examples/shell/shell_common/cmd_ping.cpp
@@ -22,6 +22,7 @@
#include <lib/core/CHIPCore.h>
#include <lib/shell/shell.h>
#include <lib/support/CodeUtils.h>
+#include <lib/support/ErrorMacros.h>
#include <lib/support/ErrorStr.h>
#include <messaging/ExchangeMgr.h>
#include <platform/CHIPDeviceLayer.h>
diff --git a/examples/shell/standalone/main.cpp b/examples/shell/standalone/main.cpp
index e1b7e10..2639a22 100644
--- a/examples/shell/standalone/main.cpp
+++ b/examples/shell/standalone/main.cpp
@@ -20,7 +20,6 @@
#include <lib/core/CHIPCore.h>
#include <lib/support/Base64.h>
#include <lib/support/CHIPArgParser.hpp>
-#include <lib/support/CodeUtils.h>
#include <lib/support/RandUtils.h>
#include <support/logging/CHIPLogging.h>
diff --git a/examples/temperature-measurement-app/esp32/main/CHIPDeviceManager.cpp b/examples/temperature-measurement-app/esp32/main/CHIPDeviceManager.cpp
index f7c5570..d1334b4 100644
--- a/examples/temperature-measurement-app/esp32/main/CHIPDeviceManager.cpp
+++ b/examples/temperature-measurement-app/esp32/main/CHIPDeviceManager.cpp
@@ -28,7 +28,7 @@
#include <app/util/basic-types.h>
#include <setup_payload/SetupPayload.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
using namespace ::chip;
diff --git a/examples/temperature-measurement-app/esp32/main/DeviceCallbacks.cpp b/examples/temperature-measurement-app/esp32/main/DeviceCallbacks.cpp
index c232b7e..c99ae36 100644
--- a/examples/temperature-measurement-app/esp32/main/DeviceCallbacks.cpp
+++ b/examples/temperature-measurement-app/esp32/main/DeviceCallbacks.cpp
@@ -28,7 +28,6 @@
#include "../gen/cluster-id.h"
#include "esp_heap_caps.h"
#include "esp_log.h"
-#include <support/CodeUtils.h>
static const char * TAG = "echo-devicecallbacks";
diff --git a/examples/tv-app/linux/main.cpp b/examples/tv-app/linux/main.cpp
index c42bfb8..f1934e7 100644
--- a/examples/tv-app/linux/main.cpp
+++ b/examples/tv-app/linux/main.cpp
@@ -28,6 +28,7 @@
#include <app/util/util.h>
#include <core/CHIPError.h>
#include <support/CHIPMem.h>
+#include <support/ErrorMacros.h>
#include <support/RandUtils.h>
#include "Server.h"
diff --git a/src/app/Command.cpp b/src/app/Command.cpp
index f068ebb..a97e9a5 100644
--- a/src/app/Command.cpp
+++ b/src/app/Command.cpp
@@ -27,6 +27,7 @@
#include "CommandSender.h"
#include "InteractionModelEngine.h"
#include <core/CHIPTLVDebug.hpp>
+#include <support/ErrorStr.h>
namespace chip {
namespace app {
diff --git a/src/app/Command.h b/src/app/Command.h
index caf0569..5b988c7 100644
--- a/src/app/Command.h
+++ b/src/app/Command.h
@@ -30,7 +30,6 @@
#include <messaging/Flags.h>
#include <protocols/Protocols.h>
#include <support/BitFlags.h>
-#include <support/CodeUtils.h>
#include <support/DLLUtil.h>
#include <support/logging/CHIPLogging.h>
#include <system/SystemPacketBuffer.h>
diff --git a/src/app/CommandHandler.cpp b/src/app/CommandHandler.cpp
index e7114d4..f2fdbed 100644
--- a/src/app/CommandHandler.cpp
+++ b/src/app/CommandHandler.cpp
@@ -28,6 +28,9 @@
#include "InteractionModelEngine.h"
#include <protocols/secure_channel/Constants.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
using GeneralStatusCode = chip::Protocols::SecureChannel::GeneralStatusCode;
diff --git a/src/app/CommandHandler.h b/src/app/CommandHandler.h
index bb4a549..2510d2b 100644
--- a/src/app/CommandHandler.h
+++ b/src/app/CommandHandler.h
@@ -31,7 +31,6 @@
#include <messaging/ExchangeMgr.h>
#include <messaging/Flags.h>
#include <protocols/Protocols.h>
-#include <support/CodeUtils.h>
#include <support/DLLUtil.h>
#include <support/logging/CHIPLogging.h>
#include <system/SystemPacketBuffer.h>
diff --git a/src/app/CommandSender.cpp b/src/app/CommandSender.cpp
index b19401f..6bdc6ea 100644
--- a/src/app/CommandSender.cpp
+++ b/src/app/CommandSender.cpp
@@ -28,6 +28,9 @@
#include "InteractionModelEngine.h"
#include <protocols/secure_channel/Constants.h>
+#include <support/DieMacros.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
using GeneralStatusCode = chip::Protocols::SecureChannel::GeneralStatusCode;
diff --git a/src/app/CommandSender.h b/src/app/CommandSender.h
index e0bbd93..a17975c 100644
--- a/src/app/CommandSender.h
+++ b/src/app/CommandSender.h
@@ -30,7 +30,6 @@
#include <messaging/ExchangeMgr.h>
#include <messaging/Flags.h>
#include <protocols/Protocols.h>
-#include <support/CodeUtils.h>
#include <support/DLLUtil.h>
#include <support/logging/CHIPLogging.h>
#include <system/SystemPacketBuffer.h>
diff --git a/src/app/InteractionModelEngine.h b/src/app/InteractionModelEngine.h
index 1a4ffdb..f5e5002 100644
--- a/src/app/InteractionModelEngine.h
+++ b/src/app/InteractionModelEngine.h
@@ -32,7 +32,6 @@
#include <messaging/Flags.h>
#include <protocols/Protocols.h>
#include <protocols/interaction_model/Constants.h>
-#include <support/CodeUtils.h>
#include <support/DLLUtil.h>
#include <support/logging/CHIPLogging.h>
#include <system/SystemPacketBuffer.h>
diff --git a/src/app/MessageDef/AttributeDataElement.h b/src/app/MessageDef/AttributeDataElement.h
index e72a5b7..db3a501 100644
--- a/src/app/MessageDef/AttributeDataElement.h
+++ b/src/app/MessageDef/AttributeDataElement.h
@@ -31,7 +31,6 @@
#include "Parser.h"
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/AttributeDataList.h b/src/app/MessageDef/AttributeDataList.h
index f88d0ad..7bb4c89 100644
--- a/src/app/MessageDef/AttributeDataList.h
+++ b/src/app/MessageDef/AttributeDataList.h
@@ -31,7 +31,6 @@
#include "ListParser.h"
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/AttributeDataVersionList.h b/src/app/MessageDef/AttributeDataVersionList.h
index 6ed49b3..4173962 100644
--- a/src/app/MessageDef/AttributeDataVersionList.h
+++ b/src/app/MessageDef/AttributeDataVersionList.h
@@ -32,7 +32,6 @@
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/AttributePath.h b/src/app/MessageDef/AttributePath.h
index d06d473..bdb870b 100644
--- a/src/app/MessageDef/AttributePath.h
+++ b/src/app/MessageDef/AttributePath.h
@@ -30,7 +30,6 @@
#include "Parser.h"
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/AttributePathList.h b/src/app/MessageDef/AttributePathList.h
index 438a061..124355d 100644
--- a/src/app/MessageDef/AttributePathList.h
+++ b/src/app/MessageDef/AttributePathList.h
@@ -32,7 +32,6 @@
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/AttributeStatusElement.h b/src/app/MessageDef/AttributeStatusElement.h
index 6cb7a74..e69c6d6 100644
--- a/src/app/MessageDef/AttributeStatusElement.h
+++ b/src/app/MessageDef/AttributeStatusElement.h
@@ -32,7 +32,6 @@
#include "StatusElement.h"
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/AttributeStatusList.h b/src/app/MessageDef/AttributeStatusList.h
index 171eda8..960e09f 100644
--- a/src/app/MessageDef/AttributeStatusList.h
+++ b/src/app/MessageDef/AttributeStatusList.h
@@ -32,7 +32,6 @@
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/Builder.cpp b/src/app/MessageDef/Builder.cpp
index ce7d97f..a09ab08 100644
--- a/src/app/MessageDef/Builder.cpp
+++ b/src/app/MessageDef/Builder.cpp
@@ -27,6 +27,9 @@
#include <stdarg.h>
#include <stdio.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
+
using namespace chip;
using namespace chip::TLV;
diff --git a/src/app/MessageDef/Builder.h b/src/app/MessageDef/Builder.h
index cd35e02..38c381f 100644
--- a/src/app/MessageDef/Builder.h
+++ b/src/app/MessageDef/Builder.h
@@ -28,7 +28,6 @@
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/CommandDataElement.h b/src/app/MessageDef/CommandDataElement.h
index d941013..3ca5b74 100644
--- a/src/app/MessageDef/CommandDataElement.h
+++ b/src/app/MessageDef/CommandDataElement.h
@@ -33,7 +33,6 @@
#include "StatusElement.h"
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/CommandList.h b/src/app/MessageDef/CommandList.h
index dc55b13..db99c07 100644
--- a/src/app/MessageDef/CommandList.h
+++ b/src/app/MessageDef/CommandList.h
@@ -32,7 +32,6 @@
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/CommandPath.h b/src/app/MessageDef/CommandPath.h
index 4a0ffdf..ebf428b 100644
--- a/src/app/MessageDef/CommandPath.h
+++ b/src/app/MessageDef/CommandPath.h
@@ -30,7 +30,6 @@
#include "Parser.h"
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/EventDataElement.h b/src/app/MessageDef/EventDataElement.h
index 6f25594..d09c06f 100644
--- a/src/app/MessageDef/EventDataElement.h
+++ b/src/app/MessageDef/EventDataElement.h
@@ -32,7 +32,6 @@
#include "Parser.h"
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/EventList.h b/src/app/MessageDef/EventList.h
index e7b1b39..e787f3b 100644
--- a/src/app/MessageDef/EventList.h
+++ b/src/app/MessageDef/EventList.h
@@ -32,7 +32,6 @@
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/EventPath.h b/src/app/MessageDef/EventPath.h
index de6e3a1..edf65a8 100644
--- a/src/app/MessageDef/EventPath.h
+++ b/src/app/MessageDef/EventPath.h
@@ -30,7 +30,6 @@
#include "Parser.h"
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/EventPathList.h b/src/app/MessageDef/EventPathList.h
index 1ccd3ed..55a57fa 100644
--- a/src/app/MessageDef/EventPathList.h
+++ b/src/app/MessageDef/EventPathList.h
@@ -33,7 +33,6 @@
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/InvokeCommand.h b/src/app/MessageDef/InvokeCommand.h
index 29ded8b..bade66c 100644
--- a/src/app/MessageDef/InvokeCommand.h
+++ b/src/app/MessageDef/InvokeCommand.h
@@ -28,7 +28,6 @@
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/ListBuilder.h b/src/app/MessageDef/ListBuilder.h
index 4672b54..265b169 100644
--- a/src/app/MessageDef/ListBuilder.h
+++ b/src/app/MessageDef/ListBuilder.h
@@ -30,7 +30,6 @@
#include "Parser.h"
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/ListParser.h b/src/app/MessageDef/ListParser.h
index 53ae4df..da1464f 100644
--- a/src/app/MessageDef/ListParser.h
+++ b/src/app/MessageDef/ListParser.h
@@ -30,7 +30,6 @@
#include "Parser.h"
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/Parser.h b/src/app/MessageDef/Parser.h
index 5d157f8..1b7dcf1 100644
--- a/src/app/MessageDef/Parser.h
+++ b/src/app/MessageDef/Parser.h
@@ -28,7 +28,7 @@
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/ReadRequest.h b/src/app/MessageDef/ReadRequest.h
index 934941d..95911fd 100644
--- a/src/app/MessageDef/ReadRequest.h
+++ b/src/app/MessageDef/ReadRequest.h
@@ -34,7 +34,6 @@
#include "Parser.h"
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/ReportData.h b/src/app/MessageDef/ReportData.h
index 22a1f28..36ef664 100644
--- a/src/app/MessageDef/ReportData.h
+++ b/src/app/MessageDef/ReportData.h
@@ -28,7 +28,6 @@
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/MessageDef/StatusElement.h b/src/app/MessageDef/StatusElement.h
index e74a591..703684a 100644
--- a/src/app/MessageDef/StatusElement.h
+++ b/src/app/MessageDef/StatusElement.h
@@ -31,7 +31,6 @@
#include <core/CHIPCore.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <util/basic-types.h>
diff --git a/src/app/ReadClient.h b/src/app/ReadClient.h
index 9f2f895..9e32168 100644
--- a/src/app/ReadClient.h
+++ b/src/app/ReadClient.h
@@ -32,7 +32,6 @@
#include <messaging/ExchangeMgr.h>
#include <messaging/Flags.h>
#include <protocols/Protocols.h>
-#include <support/CodeUtils.h>
#include <support/DLLUtil.h>
#include <support/logging/CHIPLogging.h>
#include <system/SystemPacketBuffer.h>
diff --git a/src/app/ReadHandler.h b/src/app/ReadHandler.h
index 831ee5f..3977c38 100644
--- a/src/app/ReadHandler.h
+++ b/src/app/ReadHandler.h
@@ -31,7 +31,6 @@
#include <messaging/ExchangeMgr.h>
#include <messaging/Flags.h>
#include <protocols/Protocols.h>
-#include <support/CodeUtils.h>
#include <support/DLLUtil.h>
#include <support/logging/CHIPLogging.h>
#include <system/SystemPacketBuffer.h>
diff --git a/src/app/clusters/network-commissioning/network-commissioning.cpp b/src/app/clusters/network-commissioning/network-commissioning.cpp
index 2bde913..77325b4 100644
--- a/src/app/clusters/network-commissioning/network-commissioning.cpp
+++ b/src/app/clusters/network-commissioning/network-commissioning.cpp
@@ -30,7 +30,7 @@
#include <gen/enums.h>
#include <util/af.h>
-#include <lib/support/CodeUtils.h>
+#include <lib/support/ReturnMacros.h>
#include <lib/support/SafeInt.h>
#include <lib/support/Span.h>
#include <lib/support/logging/CHIPLogging.h>
diff --git a/src/app/decoder.cpp b/src/app/decoder.cpp
index cf87792..cca765a 100644
--- a/src/app/decoder.cpp
+++ b/src/app/decoder.cpp
@@ -25,9 +25,9 @@
#include <app/chip-zcl-zpro-codec.h>
#include <app/message-reader.h>
#include <lib/core/CHIPError.h>
-#include <lib/support/CodeUtils.h>
#include <stdio.h>
#include <string.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
extern "C" {
diff --git a/src/app/server/EchoHandler.cpp b/src/app/server/EchoHandler.cpp
index 90ceda3..b336d75 100644
--- a/src/app/server/EchoHandler.cpp
+++ b/src/app/server/EchoHandler.cpp
@@ -23,6 +23,7 @@
#include <app/server/EchoHandler.h>
#include <protocols/echo/Echo.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
namespace {
diff --git a/src/app/server/Mdns.cpp b/src/app/server/Mdns.cpp
index 496fc83..577adf8 100644
--- a/src/app/server/Mdns.cpp
+++ b/src/app/server/Mdns.cpp
@@ -23,6 +23,8 @@
#include <mdns/Advertiser.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/ConfigurationManager.h>
+#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
#include <transport/AdminPairingTable.h>
#include <transport/PASESession.h>
diff --git a/src/app/server/OnboardingCodesUtil.cpp b/src/app/server/OnboardingCodesUtil.cpp
index 1c024fa..95107dd 100644
--- a/src/app/server/OnboardingCodesUtil.cpp
+++ b/src/app/server/OnboardingCodesUtil.cpp
@@ -23,7 +23,8 @@
#include <platform/CHIPDeviceLayer.h>
#include <setup_payload/ManualSetupPayloadGenerator.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
#include <support/ScopedBuffer.h>
#include <support/logging/CHIPLogging.h>
diff --git a/src/app/server/RendezvousServer.cpp b/src/app/server/RendezvousServer.cpp
index f6eda70..19c35ea 100644
--- a/src/app/server/RendezvousServer.cpp
+++ b/src/app/server/RendezvousServer.cpp
@@ -19,7 +19,9 @@
#include <app/server/SessionManager.h>
#include <core/CHIPError.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
#include <support/SafeInt.h>
#include <transport/SecureSessionMgr.h>
#include <transport/StorablePeerConnection.h>
diff --git a/src/app/server/RendezvousServer.h b/src/app/server/RendezvousServer.h
index 8d8209f..b3c4936 100644
--- a/src/app/server/RendezvousServer.h
+++ b/src/app/server/RendezvousServer.h
@@ -20,6 +20,7 @@
#include <app/server/AppDelegate.h>
#include <core/CHIPPersistentStorageDelegate.h>
#include <platform/CHIPDeviceLayer.h>
+#include <support/ReturnMacros.h>
#include <transport/RendezvousSession.h>
namespace chip {
diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp
index 48c7176..724da0a 100644
--- a/src/app/server/Server.cpp
+++ b/src/app/server/Server.cpp
@@ -32,8 +32,10 @@
#include <platform/CHIPDeviceLayer.h>
#include <platform/KeyValueStoreManager.h>
#include <setup_payload/SetupPayload.h>
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
#include <sys/param.h>
#include <system/SystemPacketBuffer.h>
diff --git a/src/app/tests/integration/chip_im_initiator.cpp b/src/app/tests/integration/chip_im_initiator.cpp
index 59e5973..5217d53 100644
--- a/src/app/tests/integration/chip_im_initiator.cpp
+++ b/src/app/tests/integration/chip_im_initiator.cpp
@@ -31,6 +31,7 @@
#include <core/CHIPCore.h>
#include <platform/CHIPDeviceLayer.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
#include <system/SystemPacketBuffer.h>
#include <transport/PASESession.h>
diff --git a/src/app/tests/integration/chip_im_responder.cpp b/src/app/tests/integration/chip_im_responder.cpp
index 666a1d2..d596f0b 100644
--- a/src/app/tests/integration/chip_im_responder.cpp
+++ b/src/app/tests/integration/chip_im_responder.cpp
@@ -33,6 +33,7 @@
#include <messaging/ExchangeMgr.h>
#include <messaging/Flags.h>
#include <platform/CHIPDeviceLayer.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
#include <system/SystemPacketBuffer.h>
#include <transport/PASESession.h>
diff --git a/src/app/tests/integration/common.cpp b/src/app/tests/integration/common.cpp
index 1182e76..0ecafab 100644
--- a/src/app/tests/integration/common.cpp
+++ b/src/app/tests/integration/common.cpp
@@ -28,6 +28,7 @@
#include <core/CHIPCore.h>
#include <core/CHIPTLVDebug.hpp>
#include <platform/CHIPDeviceLayer.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
// The ExchangeManager global object.
diff --git a/src/app/util/CHIPDeviceCallbacksMgr.cpp b/src/app/util/CHIPDeviceCallbacksMgr.cpp
index 2ab066e..9c1bc2b 100644
--- a/src/app/util/CHIPDeviceCallbacksMgr.cpp
+++ b/src/app/util/CHIPDeviceCallbacksMgr.cpp
@@ -28,6 +28,7 @@
#include <core/CHIPCore.h>
#include <inttypes.h>
+#include <support/ReturnMacros.h>
namespace {
struct ResponseCallbackInfo
diff --git a/src/app/util/ember-compatibility-functions.cpp b/src/app/util/ember-compatibility-functions.cpp
index 981ec25..aaf3929 100644
--- a/src/app/util/ember-compatibility-functions.cpp
+++ b/src/app/util/ember-compatibility-functions.cpp
@@ -26,7 +26,6 @@
#include <app/Command.h>
#include <lib/core/CHIPCore.h>
#include <lib/core/CHIPTLV.h>
-#include <lib/support/CodeUtils.h>
#include <util/util.h>
namespace chip {
diff --git a/src/app/zap-templates/templates/chip/CHIPClusters-src.zapt b/src/app/zap-templates/templates/chip/CHIPClusters-src.zapt
index f5e9e7b..62126b5 100644
--- a/src/app/zap-templates/templates/chip/CHIPClusters-src.zapt
+++ b/src/app/zap-templates/templates/chip/CHIPClusters-src.zapt
@@ -5,6 +5,7 @@
#include <app/chip-zcl-zpro-codec-api.h>
#include <lib/support/Span.h>
+#include <support/ReturnMacros.h>
namespace chip {
namespace Controller {
diff --git a/src/app/zap-templates/templates/chip/python-ChipDeviceController-ClusterCommands.zapt b/src/app/zap-templates/templates/chip/python-ChipDeviceController-ClusterCommands.zapt
index e4953de..a886acf 100644
--- a/src/app/zap-templates/templates/chip/python-ChipDeviceController-ClusterCommands.zapt
+++ b/src/app/zap-templates/templates/chip/python-ChipDeviceController-ClusterCommands.zapt
@@ -5,6 +5,7 @@
#include <app/CommandSender.h>
#include <app/InteractionModelEngine.h>
#include <lib/support/Span.h>
+#include <support/ReturnMacros.h>
#include <controller/CHIPClusters.h>
#include <controller/CHIPDevice.h>
diff --git a/src/ble/BLEEndPoint.cpp b/src/ble/BLEEndPoint.cpp
index c942f41..98a1faa 100644
--- a/src/ble/BLEEndPoint.cpp
+++ b/src/ble/BLEEndPoint.cpp
@@ -39,6 +39,7 @@
#include <support/BitFlags.h>
#include <support/CHIPFaultInjection.h>
#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <ble/BLEEndPoint.h>
diff --git a/src/ble/BleLayer.cpp b/src/ble/BleLayer.cpp
index 0117311..183aafc 100644
--- a/src/ble/BleLayer.cpp
+++ b/src/ble/BleLayer.cpp
@@ -63,7 +63,7 @@
#include <ble/BleUUID.h>
#include <core/CHIPEncoding.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
// Magic values expected in first 2 bytes of valid BLE transport capabilities request or response:
diff --git a/src/ble/BtpEngine.cpp b/src/ble/BtpEngine.cpp
index 4b62c98..b6f50f9 100644
--- a/src/ble/BtpEngine.cpp
+++ b/src/ble/BtpEngine.cpp
@@ -36,6 +36,7 @@
#include <support/BufferReader.h>
#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
// Define below to enable extremely verbose BLE-specific debug logging.
diff --git a/src/controller/CHIPClusters.cpp b/src/controller/CHIPClusters.cpp
index a2bac1c..61f73d5 100644
--- a/src/controller/CHIPClusters.cpp
+++ b/src/controller/CHIPClusters.cpp
@@ -22,6 +22,7 @@
#include <app/chip-zcl-zpro-codec-api.h>
#include <lib/support/Span.h>
+#include <support/ReturnMacros.h>
namespace chip {
namespace Controller {
diff --git a/src/controller/CHIPDevice.cpp b/src/controller/CHIPDevice.cpp
index 36cf324..183e293 100644
--- a/src/controller/CHIPDevice.cpp
+++ b/src/controller/CHIPDevice.cpp
@@ -42,8 +42,9 @@
#include <core/CHIPSafeCasts.h>
#include <support/Base64.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
#include <support/SafeInt.h>
#include <support/logging/CHIPLogging.h>
#include <system/TLVPacketBufferBackingStore.h>
diff --git a/src/controller/CHIPDevice.h b/src/controller/CHIPDevice.h
index 27d40da..1c43735 100644
--- a/src/controller/CHIPDevice.h
+++ b/src/controller/CHIPDevice.h
@@ -35,6 +35,7 @@
#include <setup_payload/SetupPayload.h>
#include <support/Base64.h>
#include <support/DLLUtil.h>
+#include <support/DieMacros.h>
#include <transport/PASESession.h>
#include <transport/SecureSessionMgr.h>
#include <transport/TransportMgr.h>
diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp
index 8fe5274..5d82e75 100644
--- a/src/controller/CHIPDeviceController.cpp
+++ b/src/controller/CHIPDeviceController.cpp
@@ -47,8 +47,9 @@
#include <support/Base64.h>
#include <support/CHIPArgParser.hpp>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
#include <support/SafeInt.h>
#include <support/TimeUtils.h>
#include <support/logging/CHIPLogging.h>
diff --git a/src/controller/DeviceAddressUpdater.cpp b/src/controller/DeviceAddressUpdater.cpp
index 97de6b8..985f1bf 100644
--- a/src/controller/DeviceAddressUpdater.cpp
+++ b/src/controller/DeviceAddressUpdater.cpp
@@ -19,6 +19,8 @@
#include "DeviceAddressUpdater.h"
#include <controller/CHIPDeviceController.h>
+#include <support/ErrorMacros.h>
+#include <support/ReturnMacros.h>
namespace chip {
namespace Controller {
diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp
index 1e5d13d..9792063 100644
--- a/src/controller/java/CHIPDeviceController-JNI.cpp
+++ b/src/controller/java/CHIPDeviceController-JNI.cpp
@@ -35,8 +35,9 @@
#include <jni.h>
#include <pthread.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
#include <support/SafeInt.h>
#include <support/logging/CHIPLogging.h>
diff --git a/src/controller/python/ChipDeviceController-ClusterCommands.cpp b/src/controller/python/ChipDeviceController-ClusterCommands.cpp
index 937f63c..611fe61 100644
--- a/src/controller/python/ChipDeviceController-ClusterCommands.cpp
+++ b/src/controller/python/ChipDeviceController-ClusterCommands.cpp
@@ -22,6 +22,7 @@
#include <app/CommandSender.h>
#include <app/InteractionModelEngine.h>
#include <lib/support/Span.h>
+#include <support/ReturnMacros.h>
#include <controller/CHIPClusters.h>
#include <controller/CHIPDevice.h>
diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp
index 6972f1c..b7b3036 100644
--- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp
+++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp
@@ -50,8 +50,10 @@
#include <controller/DeviceAddressUpdater.h>
#include <mdns/Resolver.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <support/DLLUtil.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
using namespace chip;
diff --git a/src/controller/python/chip/ble/LinuxImpl.cpp b/src/controller/python/chip/ble/LinuxImpl.cpp
index bbed0b6..511f35f 100644
--- a/src/controller/python/chip/ble/LinuxImpl.cpp
+++ b/src/controller/python/chip/ble/LinuxImpl.cpp
@@ -4,6 +4,7 @@
#include <platform/Linux/bluez/MainLoop.h>
#include <platform/internal/BLEManager.h>
#include <support/CHIPMem.h>
+#include <support/ReturnMacros.h>
using namespace chip::DeviceLayer::Internal;
diff --git a/src/controller/python/chip/ble/darwin/AdapterListing.mm b/src/controller/python/chip/ble/darwin/AdapterListing.mm
index 51a55b6..001d14b 100644
--- a/src/controller/python/chip/ble/darwin/AdapterListing.mm
+++ b/src/controller/python/chip/ble/darwin/AdapterListing.mm
@@ -1,4 +1,5 @@
#include <support/CHIPMem.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
#import <CoreBluetooth/CoreBluetooth.h>
diff --git a/src/controller/python/chip/ble/darwin/Scanning.mm b/src/controller/python/chip/ble/darwin/Scanning.mm
index a68f0cb..79623e9 100644
--- a/src/controller/python/chip/ble/darwin/Scanning.mm
+++ b/src/controller/python/chip/ble/darwin/Scanning.mm
@@ -2,6 +2,7 @@
#include <ble/CHIPBleServiceData.h>
#include <platform/Darwin/UUIDHelper.h>
#include <support/CHIPMem.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
#import <CoreBluetooth/CoreBluetooth.h>
diff --git a/src/controller/python/chip/internal/CommissionerImpl.cpp b/src/controller/python/chip/internal/CommissionerImpl.cpp
index 0aa1ab4..a8d5c91 100644
--- a/src/controller/python/chip/internal/CommissionerImpl.cpp
+++ b/src/controller/python/chip/internal/CommissionerImpl.cpp
@@ -19,6 +19,7 @@
#include <controller/CHIPDeviceController.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/KeyValueStoreManager.h>
+#include <support/ErrorStr.h>
#include <support/logging/CHIPLogging.h>
#include "ChipThreadWork.h"
diff --git a/src/credentials/CHIPCert.cpp b/src/credentials/CHIPCert.cpp
index 1e7023d..e31e3a4 100644
--- a/src/credentials/CHIPCert.cpp
+++ b/src/credentials/CHIPCert.cpp
@@ -39,7 +39,7 @@
#include <credentials/CHIPCert.h>
#include <protocols/Protocols.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/TimeUtils.h>
namespace chip {
diff --git a/src/credentials/CHIPCertFromX509.cpp b/src/credentials/CHIPCertFromX509.cpp
index 428be7e..0c9900b 100644
--- a/src/credentials/CHIPCertFromX509.cpp
+++ b/src/credentials/CHIPCertFromX509.cpp
@@ -37,7 +37,7 @@
#include <core/CHIPTLV.h>
#include <credentials/CHIPCert.h>
#include <protocols/Protocols.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
namespace chip {
namespace Credentials {
diff --git a/src/credentials/CHIPCertToX509.cpp b/src/credentials/CHIPCertToX509.cpp
index 11e52b3..ece27d1 100644
--- a/src/credentials/CHIPCertToX509.cpp
+++ b/src/credentials/CHIPCertToX509.cpp
@@ -38,8 +38,8 @@
#include <core/CHIPTLV.h>
#include <credentials/CHIPCert.h>
#include <protocols/Protocols.h>
-#include <support/CodeUtils.h>
#include <support/DLLUtil.h>
+#include <support/ErrorMacros.h>
namespace chip {
namespace Credentials {
diff --git a/src/credentials/tests/CHIPCert_test_vectors.h b/src/credentials/tests/CHIPCert_test_vectors.h
index 15cd65f..4c0e5b9 100644
--- a/src/credentials/tests/CHIPCert_test_vectors.h
+++ b/src/credentials/tests/CHIPCert_test_vectors.h
@@ -29,7 +29,6 @@
#include <asn1/ASN1OID.h>
#include <core/CHIPConfig.h>
#include <support/BitFlags.h>
-#include <support/CodeUtils.h>
namespace chip {
namespace TestCerts {
diff --git a/src/credentials/tests/TestChipCert.cpp b/src/credentials/tests/TestChipCert.cpp
index 92ffdc1..df2b109 100644
--- a/src/credentials/tests/TestChipCert.cpp
+++ b/src/credentials/tests/TestChipCert.cpp
@@ -27,7 +27,7 @@
#include <core/CHIPTLV.h>
#include <credentials/CHIPCert.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
#include <support/UnitTestRegistration.h>
diff --git a/src/crypto/CHIPCryptoPAL.cpp b/src/crypto/CHIPCryptoPAL.cpp
index a6b6085..b3421ad 100644
--- a/src/crypto/CHIPCryptoPAL.cpp
+++ b/src/crypto/CHIPCryptoPAL.cpp
@@ -22,7 +22,7 @@
#include "CHIPCryptoPAL.h"
#include <string.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
namespace chip {
namespace Crypto {
diff --git a/src/crypto/CHIPCryptoPAL.h b/src/crypto/CHIPCryptoPAL.h
index 8cef9a0..b8c5779 100644
--- a/src/crypto/CHIPCryptoPAL.h
+++ b/src/crypto/CHIPCryptoPAL.h
@@ -28,7 +28,7 @@
#endif
#include <core/CHIPError.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <stddef.h>
#include <string.h>
diff --git a/src/crypto/CHIPCryptoPALOpenSSL.cpp b/src/crypto/CHIPCryptoPALOpenSSL.cpp
index 9d220ab..cbf132e 100644
--- a/src/crypto/CHIPCryptoPALOpenSSL.cpp
+++ b/src/crypto/CHIPCryptoPALOpenSSL.cpp
@@ -40,7 +40,7 @@
#include <core/CHIPSafeCasts.h>
#include <support/BufferWriter.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/SafeInt.h>
#include <support/SafePointerCast.h>
#include <support/logging/CHIPLogging.h>
diff --git a/src/crypto/CHIPCryptoPALmbedTLS.cpp b/src/crypto/CHIPCryptoPALmbedTLS.cpp
index 6dab7dd..6dcf2fa 100644
--- a/src/crypto/CHIPCryptoPALmbedTLS.cpp
+++ b/src/crypto/CHIPCryptoPALmbedTLS.cpp
@@ -40,7 +40,7 @@
#include <core/CHIPSafeCasts.h>
#include <support/BufferWriter.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/SafePointerCast.h>
#include <support/logging/CHIPLogging.h>
diff --git a/src/include/platform/ConnectivityManager.h b/src/include/platform/ConnectivityManager.h
index 0b38b7b..e6310de 100644
--- a/src/include/platform/ConnectivityManager.h
+++ b/src/include/platform/ConnectivityManager.h
@@ -23,8 +23,6 @@
#pragma once
-#include <support/CodeUtils.h>
-
namespace chip {
namespace Ble {
diff --git a/src/include/platform/internal/BLEManager.h b/src/include/platform/internal/BLEManager.h
index 9310a1d..53a0d96 100644
--- a/src/include/platform/internal/BLEManager.h
+++ b/src/include/platform/internal/BLEManager.h
@@ -25,7 +25,6 @@
#pragma once
#include <platform/ConnectivityManager.h>
-#include <support/CodeUtils.h>
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.cpp b/src/include/platform/internal/GenericConfigurationManagerImpl.cpp
index 739cebf..454d5d3 100644
--- a/src/include/platform/internal/GenericConfigurationManagerImpl.cpp
+++ b/src/include/platform/internal/GenericConfigurationManagerImpl.cpp
@@ -32,8 +32,9 @@
#include <platform/internal/GenericConfigurationManagerImpl.h>
#include <support/Base64.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/ScopedBuffer.h>
+#include <support/logging/CHIPLogging.h>
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
#include <platform/ThreadStackManager.h>
diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.cpp b/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.cpp
index da76c0c..282a341 100644
--- a/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.cpp
+++ b/src/include/platform/internal/GenericConnectivityManagerImpl_Thread.cpp
@@ -27,7 +27,8 @@
#include <platform/internal/CHIPDeviceLayerInternal.h>
#include <platform/internal/GenericConnectivityManagerImpl_Thread.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/logging/CHIPLogging.h>
namespace chip {
namespace DeviceLayer {
diff --git a/src/include/platform/internal/GenericConnectivityManagerImpl_WiFi.cpp b/src/include/platform/internal/GenericConnectivityManagerImpl_WiFi.cpp
index f8103d4..aa408dc 100644
--- a/src/include/platform/internal/GenericConnectivityManagerImpl_WiFi.cpp
+++ b/src/include/platform/internal/GenericConnectivityManagerImpl_WiFi.cpp
@@ -26,7 +26,6 @@
#include <platform/internal/CHIPDeviceLayerInternal.h>
#include <platform/internal/GenericConnectivityManagerImpl_WiFi.h>
-#include <support/CodeUtils.h>
namespace chip {
namespace DeviceLayer {
diff --git a/src/include/platform/internal/GenericPlatformManagerImpl.cpp b/src/include/platform/internal/GenericPlatformManagerImpl.cpp
index c2e52d0..8bfe783 100644
--- a/src/include/platform/internal/GenericPlatformManagerImpl.cpp
+++ b/src/include/platform/internal/GenericPlatformManagerImpl.cpp
@@ -33,7 +33,8 @@
#include <platform/internal/GenericPlatformManagerImpl.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
#include <support/logging/CHIPLogging.h>
namespace chip {
diff --git a/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.cpp b/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.cpp
index 3afa06c..1c600a9 100644
--- a/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.cpp
+++ b/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.cpp
@@ -28,6 +28,9 @@
#include <platform/PlatformManager.h>
#include <platform/internal/CHIPDeviceLayerInternal.h>
#include <platform/internal/GenericPlatformManagerImpl_FreeRTOS.h>
+#include <support/DieMacros.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
// Include the non-inline definitions for the GenericPlatformManagerImpl<> template,
// from which the GenericPlatformManagerImpl_FreeRTOS<> template inherits.
diff --git a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.cpp b/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.cpp
index e1ce027..486c5b1 100644
--- a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.cpp
+++ b/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.cpp
@@ -34,10 +34,12 @@
#include <platform/internal/CHIPDeviceLayerInternal.h>
#include <platform/internal/GenericSoftwareUpdateManagerImpl.h>
+#include <support/ErrorMacros.h>
#include <support/FibonacciUtils.h>
#include <support/RandUtils.h>
#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
namespace chip {
diff --git a/src/include/platform/internal/testing/ConfigUnitTest.h b/src/include/platform/internal/testing/ConfigUnitTest.h
index 3bcf9bb..bf3ac90 100644
--- a/src/include/platform/internal/testing/ConfigUnitTest.h
+++ b/src/include/platform/internal/testing/ConfigUnitTest.h
@@ -20,7 +20,7 @@
#pragma once
#include <core/CHIPCore.h>
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
namespace chip {
namespace DeviceLayer {
diff --git a/src/inet/AsyncDNSResolverSockets.cpp b/src/inet/AsyncDNSResolverSockets.cpp
index 6dcb157..6228381 100644
--- a/src/inet/AsyncDNSResolverSockets.cpp
+++ b/src/inet/AsyncDNSResolverSockets.cpp
@@ -23,7 +23,8 @@
*
*/
#include <inet/InetLayer.h>
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <errno.h>
diff --git a/src/inet/DNSResolver.cpp b/src/inet/DNSResolver.cpp
index b217532..109f656 100644
--- a/src/inet/DNSResolver.cpp
+++ b/src/inet/DNSResolver.cpp
@@ -29,6 +29,7 @@
#include <inet/InetLayerEvents.h>
#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
#include <string.h>
diff --git a/src/inet/IPAddress-StringFuncts.cpp b/src/inet/IPAddress-StringFuncts.cpp
index a73e560..10f7dfb 100644
--- a/src/inet/IPAddress-StringFuncts.cpp
+++ b/src/inet/IPAddress-StringFuncts.cpp
@@ -31,7 +31,6 @@
#include <string.h>
#include <inet/InetLayer.h>
-#include <support/CodeUtils.h>
#if !CHIP_SYSTEM_CONFIG_USE_LWIP
#include <arpa/inet.h>
diff --git a/src/inet/IPEndPointBasis.cpp b/src/inet/IPEndPointBasis.cpp
index f2c682b..3316902 100644
--- a/src/inet/IPEndPointBasis.cpp
+++ b/src/inet/IPEndPointBasis.cpp
@@ -37,7 +37,9 @@
#include <inet/InetLayer.h>
#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/SafeInt.h>
+#include <support/logging/CHIPLogging.h>
#if CHIP_SYSTEM_CONFIG_USE_LWIP
#if INET_CONFIG_ENABLE_IPV4
diff --git a/src/inet/InetInterface.cpp b/src/inet/InetInterface.cpp
index 5641caa..4a6d2a9 100644
--- a/src/inet/InetInterface.cpp
+++ b/src/inet/InetInterface.cpp
@@ -33,8 +33,8 @@
#include "InetLayerEvents.h"
#include <support/CHIPMemString.h>
-#include <support/CodeUtils.h>
#include <support/DLLUtil.h>
+#include <support/ErrorMacros.h>
#if CHIP_SYSTEM_CONFIG_USE_LWIP
#include <lwip/netif.h>
diff --git a/src/inet/InetLayer.cpp b/src/inet/InetLayer.cpp
index e7fe2ac..08171b9 100644
--- a/src/inet/InetLayer.cpp
+++ b/src/inet/InetLayer.cpp
@@ -50,7 +50,7 @@
#include <system/SystemTimer.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <errno.h>
diff --git a/src/inet/RawEndPoint.cpp b/src/inet/RawEndPoint.cpp
index afdc8bd..b280ca2 100644
--- a/src/inet/RawEndPoint.cpp
+++ b/src/inet/RawEndPoint.cpp
@@ -34,7 +34,7 @@
#include "InetFaultInjection.h"
#include <inet/InetLayer.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <system/SystemFaultInjection.h>
diff --git a/src/inet/TCPEndPoint.cpp b/src/inet/TCPEndPoint.cpp
index c15546a..0a35cbe 100644
--- a/src/inet/TCPEndPoint.cpp
+++ b/src/inet/TCPEndPoint.cpp
@@ -37,7 +37,8 @@
#include "InetFaultInjection.h"
#include <inet/InetLayer.h>
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
+#include <support/ErrorMacros.h>
#include <support/SafeInt.h>
#include <support/logging/CHIPLogging.h>
#include <system/SystemFaultInjection.h>
diff --git a/src/inet/UDPEndPoint.cpp b/src/inet/UDPEndPoint.cpp
index c2b3c81..7525aa2 100644
--- a/src/inet/UDPEndPoint.cpp
+++ b/src/inet/UDPEndPoint.cpp
@@ -33,7 +33,7 @@
#include "InetFaultInjection.h"
#include <inet/InetLayer.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <system/SystemFaultInjection.h>
diff --git a/src/inet/tests/TestInetAddress.cpp b/src/inet/tests/TestInetAddress.cpp
index 0c8e107..cf453c4 100644
--- a/src/inet/tests/TestInetAddress.cpp
+++ b/src/inet/tests/TestInetAddress.cpp
@@ -45,7 +45,6 @@
#include <inet/IPPrefix.h>
-#include <support/CodeUtils.h>
#include <support/UnitTestRegistration.h>
using namespace chip;
diff --git a/src/inet/tests/TestInetCommon.h b/src/inet/tests/TestInetCommon.h
index 7bd68f0..a02b66a 100644
--- a/src/inet/tests/TestInetCommon.h
+++ b/src/inet/tests/TestInetCommon.h
@@ -40,7 +40,6 @@
#include <sys/time.h>
#include <inet/InetLayer.h>
-#include <support/CodeUtils.h>
#include <system/SystemLayer.h>
#define CHIP_TOOL_COPYRIGHT "Copyright (c) 2020 Project CHIP Authors\nAll rights reserved.\n"
diff --git a/src/inet/tests/TestInetEndPoint.cpp b/src/inet/tests/TestInetEndPoint.cpp
index d8cb6e9..991cd68 100644
--- a/src/inet/tests/TestInetEndPoint.cpp
+++ b/src/inet/tests/TestInetEndPoint.cpp
@@ -40,7 +40,6 @@
#include <support/CHIPArgParser.hpp>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <support/UnitTestRegistration.h>
#include <system/SystemError.h>
diff --git a/src/inet/tests/TestInetErrorStr.cpp b/src/inet/tests/TestInetErrorStr.cpp
index fa95072..aad86a1 100644
--- a/src/inet/tests/TestInetErrorStr.cpp
+++ b/src/inet/tests/TestInetErrorStr.cpp
@@ -37,7 +37,6 @@
#include <string.h>
#include <inet/InetError.h>
-#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
#include <support/UnitTestRegistration.h>
diff --git a/src/inet/tests/TestInetLayer.cpp b/src/inet/tests/TestInetLayer.cpp
index 516abc9..61318ab 100644
--- a/src/inet/tests/TestInetLayer.cpp
+++ b/src/inet/tests/TestInetLayer.cpp
@@ -39,6 +39,8 @@
#include <inet/InetArgParser.h>
#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
#include <system/SystemTimer.h>
diff --git a/src/inet/tests/TestInetLayerCommon.cpp b/src/inet/tests/TestInetLayerCommon.cpp
index 624a507..8a33a36 100644
--- a/src/inet/tests/TestInetLayerCommon.cpp
+++ b/src/inet/tests/TestInetLayerCommon.cpp
@@ -35,7 +35,8 @@
#include <inet/InetLayer.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
#include "TestInetCommon.h"
diff --git a/src/inet/tests/TestInetLayerDNS.cpp b/src/inet/tests/TestInetLayerDNS.cpp
index 79648cf..bfef6ba 100644
--- a/src/inet/tests/TestInetLayerDNS.cpp
+++ b/src/inet/tests/TestInetLayerDNS.cpp
@@ -37,7 +37,7 @@
#include <CHIPVersion.h>
#include <inet/InetLayer.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorStr.h>
#include <support/UnitTestRegistration.h>
#include <system/SystemClock.h>
diff --git a/src/inet/tests/TestInetLayerMulticast.cpp b/src/inet/tests/TestInetLayerMulticast.cpp
index 04a06b6..ffe8ff9 100644
--- a/src/inet/tests/TestInetLayerMulticast.cpp
+++ b/src/inet/tests/TestInetLayerMulticast.cpp
@@ -42,6 +42,7 @@
#include <inet/IPAddress.h>
#include <inet/InetArgParser.h>
#include <support/CHIPArgParser.hpp>
+#include <support/ErrorMacros.h>
#include <system/SystemTimer.h>
#include "TestInetCommon.h"
diff --git a/src/inet/tests/TestSetupFaultInjectionPosix.cpp b/src/inet/tests/TestSetupFaultInjectionPosix.cpp
index 6a525bd..c7f7ed1 100644
--- a/src/inet/tests/TestSetupFaultInjectionPosix.cpp
+++ b/src/inet/tests/TestSetupFaultInjectionPosix.cpp
@@ -31,7 +31,7 @@
#include <inet/InetFaultInjection.h>
#include <stdio.h>
#include <support/CHIPFaultInjection.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/ScopedBuffer.h>
#include <system/SystemFaultInjection.h>
diff --git a/src/lib/asn1/ASN1Macros.h b/src/lib/asn1/ASN1Macros.h
index 6f4de82..2a29cb4 100644
--- a/src/lib/asn1/ASN1Macros.h
+++ b/src/lib/asn1/ASN1Macros.h
@@ -26,7 +26,7 @@
#pragma once
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
// Local variable names used by utility macros.
diff --git a/src/lib/asn1/ASN1Writer.cpp b/src/lib/asn1/ASN1Writer.cpp
index 241f4f9..0edda1a 100644
--- a/src/lib/asn1/ASN1Writer.cpp
+++ b/src/lib/asn1/ASN1Writer.cpp
@@ -37,7 +37,7 @@
#include <core/CHIPCore.h>
#include <core/CHIPEncoding.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
+#include <support/ReturnMacros.h>
namespace chip {
namespace ASN1 {
diff --git a/src/lib/core/CHIPCircularTLVBuffer.cpp b/src/lib/core/CHIPCircularTLVBuffer.cpp
index a278343..0761608 100644
--- a/src/lib/core/CHIPCircularTLVBuffer.cpp
+++ b/src/lib/core/CHIPCircularTLVBuffer.cpp
@@ -36,7 +36,7 @@
#include <core/CHIPEncoding.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
+#include <support/ReturnMacros.h>
#include <stdint.h>
diff --git a/src/lib/core/CHIPKeyIds.cpp b/src/lib/core/CHIPKeyIds.cpp
index 19d2d2e..a489eaa 100644
--- a/src/lib/core/CHIPKeyIds.cpp
+++ b/src/lib/core/CHIPKeyIds.cpp
@@ -24,7 +24,7 @@
#include "CHIPKeyIds.h"
#include <core/CHIPCore.h>
-#include <support/CodeUtils.h>
+#include <support/ReturnMacros.h>
namespace chip {
diff --git a/src/lib/core/CHIPTLVDebug.cpp b/src/lib/core/CHIPTLVDebug.cpp
index 4999595..531ec42 100644
--- a/src/lib/core/CHIPTLVDebug.cpp
+++ b/src/lib/core/CHIPTLVDebug.cpp
@@ -34,7 +34,8 @@
#include <core/CHIPTLV.h>
#include <core/CHIPTLVDebug.hpp>
#include <core/CHIPTLVUtilities.hpp>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
namespace chip {
diff --git a/src/lib/core/CHIPTLVReader.cpp b/src/lib/core/CHIPTLVReader.cpp
index d4f8b01..e670499 100644
--- a/src/lib/core/CHIPTLVReader.cpp
+++ b/src/lib/core/CHIPTLVReader.cpp
@@ -28,8 +28,10 @@
#include <core/CHIPEncoding.h>
#include <core/CHIPTLV.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ReturnMacros.h>
#include <support/SafeInt.h>
+#include <support/logging/CHIPLogging.h>
namespace chip {
namespace TLV {
diff --git a/src/lib/core/CHIPTLVUpdater.cpp b/src/lib/core/CHIPTLVUpdater.cpp
index e07da10..29e159e 100644
--- a/src/lib/core/CHIPTLVUpdater.cpp
+++ b/src/lib/core/CHIPTLVUpdater.cpp
@@ -26,7 +26,7 @@
#include <core/CHIPCore.h>
#include <core/CHIPEncoding.h>
#include <core/CHIPTLV.h>
-#include <support/CodeUtils.h>
+#include <support/ReturnMacros.h>
namespace chip {
namespace TLV {
diff --git a/src/lib/core/CHIPTLVUtilities.cpp b/src/lib/core/CHIPTLVUtilities.cpp
index 0b7d679..07856bf 100644
--- a/src/lib/core/CHIPTLVUtilities.cpp
+++ b/src/lib/core/CHIPTLVUtilities.cpp
@@ -25,7 +25,7 @@
#include <core/CHIPTLVDebug.hpp>
#include <core/CHIPTLVUtilities.hpp>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
namespace chip {
diff --git a/src/lib/core/CHIPTLVWriter.cpp b/src/lib/core/CHIPTLVWriter.cpp
index 4155302..1e25fb5 100644
--- a/src/lib/core/CHIPTLVWriter.cpp
+++ b/src/lib/core/CHIPTLVWriter.cpp
@@ -31,7 +31,8 @@
#include <core/CHIPEncoding.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ReturnMacros.h>
#include <support/SafeInt.h>
#include <stdarg.h>
diff --git a/src/lib/core/tests/TestCHIPTLV.cpp b/src/lib/core/tests/TestCHIPTLV.cpp
index 0fc4bbe..3dd35e8 100644
--- a/src/lib/core/tests/TestCHIPTLV.cpp
+++ b/src/lib/core/tests/TestCHIPTLV.cpp
@@ -34,8 +34,9 @@
#include <core/CHIPTLVUtilities.hpp>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/RandUtils.h>
+#include <support/ReturnMacros.h>
#include <support/ScopedBuffer.h>
#include <support/UnitTestRegistration.h>
diff --git a/src/lib/mdns/Advertiser_ImplMinimalMdns.cpp b/src/lib/mdns/Advertiser_ImplMinimalMdns.cpp
index 8229a23..abb5f38 100644
--- a/src/lib/mdns/Advertiser_ImplMinimalMdns.cpp
+++ b/src/lib/mdns/Advertiser_ImplMinimalMdns.cpp
@@ -30,8 +30,11 @@
#include <mdns/minimal/responders/Srv.h>
#include <mdns/minimal/responders/Txt.h>
#include <support/CHIPMem.h>
+#include <support/ErrorStr.h>
#include <support/RandUtils.h>
+#include <support/ReturnMacros.h>
#include <support/StringBuilder.h>
+#include <support/logging/CHIPLogging.h>
// Enable detailed mDNS logging for received queries
#undef DETAIL_LOGGING
diff --git a/src/lib/mdns/Discovery_ImplPlatform.cpp b/src/lib/mdns/Discovery_ImplPlatform.cpp
index d83ded6..d7ed0f8 100644
--- a/src/lib/mdns/Discovery_ImplPlatform.cpp
+++ b/src/lib/mdns/Discovery_ImplPlatform.cpp
@@ -22,6 +22,7 @@
#include "ServiceNaming.h"
#include "lib/core/CHIPSafeCasts.h"
#include "lib/mdns/platform/Mdns.h"
+#include "lib/support/ReturnMacros.h"
#include "lib/support/logging/CHIPLogging.h"
#include "platform/CHIPDeviceConfig.h"
#include "platform/CHIPDeviceLayer.h"
diff --git a/src/lib/mdns/minimal/ResponseSender.cpp b/src/lib/mdns/minimal/ResponseSender.cpp
index 51596fc..7278831 100644
--- a/src/lib/mdns/minimal/ResponseSender.cpp
+++ b/src/lib/mdns/minimal/ResponseSender.cpp
@@ -19,6 +19,8 @@
#include "QueryReplyFilter.h"
+#include <support/ReturnMacros.h>
+#include <support/logging/CHIPLogging.h>
#include <system/SystemClock.h>
#define RETURN_IF_ERROR(err) \
diff --git a/src/lib/mdns/minimal/Server.cpp b/src/lib/mdns/minimal/Server.cpp
index c6432df..bbed711 100644
--- a/src/lib/mdns/minimal/Server.cpp
+++ b/src/lib/mdns/minimal/Server.cpp
@@ -21,6 +21,9 @@
#include <utility>
#include <mdns/minimal/core/DnsHeader.h>
+#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
+#include <support/logging/CHIPLogging.h>
namespace mdns {
namespace Minimal {
diff --git a/src/lib/shell/shell.cpp b/src/lib/shell/shell.cpp
index 62e3716..a9be97d 100644
--- a/src/lib/shell/shell.cpp
+++ b/src/lib/shell/shell.cpp
@@ -25,7 +25,7 @@
#include "commands.h"
#include <core/CHIPError.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <assert.h>
diff --git a/src/lib/support/BUILD.gn b/src/lib/support/BUILD.gn
index 9ba5e5c..5e8c119 100644
--- a/src/lib/support/BUILD.gn
+++ b/src/lib/support/BUILD.gn
@@ -69,6 +69,8 @@
"CHIPPlatformMemory.h",
"CodeUtils.h",
"DLLUtil.h",
+ "DieMacros.h",
+ "ErrorMacros.h",
"ErrorStr.cpp",
"ErrorStr.h",
"FibonacciUtils.cpp",
@@ -83,6 +85,7 @@
"PrivateHeap.h",
"RandUtils.cpp",
"RandUtils.h",
+ "ReturnMacros.h",
"SafeInt.h",
"SerializableIntegerSet.cpp",
"SerializableIntegerSet.h",
diff --git a/src/lib/support/CodeUtils.h b/src/lib/support/CodeUtils.h
index 9e198bc..09baa49 100644
--- a/src/lib/support/CodeUtils.h
+++ b/src/lib/support/CodeUtils.h
@@ -26,95 +26,14 @@
#pragma once
+// TODO: Remove transitional includes (these headers are not used here)
#include <core/CHIPError.h>
+#include <support/DieMacros.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
-/**
- * @name chip-specific nlassert.h Overrides
- *
- * @{
- *
- */
-
-/**
- * @def CHIP_ASSERT_ABORT()
- *
- * @brief
- * This implements a chip-specific override for #CHIP_ASSERT_ABORT *
- * from nlassert.h.
- *
- */
-#if !defined(CHIP_ASSERT_ABORT)
-#define CHIP_ASSERT_ABORT() chipDie()
-#endif
-
-/**
- * @def CHIP_ASSERT_LOG(aPrefix, aName, aCondition, aLabel, aFile, aLine, aMessage)
- *
- * @brief
- * This implements a chip-specific override for \c CHIP_ASSERT_LOG
- * from nlassert.h.
- *
- * @param[in] aPrefix A pointer to a NULL-terminated C string printed
- * at the beginning of the logged assertion
- * message. Typically this is and should be
- * \c CHIP_ASSERT_PREFIX_STRING.
- * @param[in] aName A pointer to a NULL-terminated C string printed
- * following @a aPrefix that indicates what
- * module, program, application or subsystem
- * the assertion occurred in Typically this
- * is and should be
- * \c CHIP_ASSERT_COMPONENT_STRING.
- * @param[in] aCondition A pointer to a NULL-terminated C string indicating
- * the expression that evaluated to false in
- * the assertion. Typically this is a
- * stringified version of the actual
- * assertion expression.
- * @param[in] aLabel An optional pointer to a NULL-terminated C string
- * indicating, for exception-style
- * assertions, the label that will be
- * branched to when the assertion expression
- * evaluates to false.
- * @param[in] aFile A pointer to a NULL-terminated C string indicating
- * the file in which the exception
- * occurred. Typically this is and should be
- * \_\_FILE\_\_ from the C preprocessor.
- * @param[in] aLine The line number in @a aFile on which the assertion
- * expression evaluated to false. Typically
- * this is and should be \_\_LINE\_\_ from the C
- * preprocessor.
- * @param[in] aMessage An optional pointer to a NULL-terminated C string
- * containing a caller-specified message
- * further describing the assertion failure.
- *
- */
-// clang-format off
-#if !defined(CHIP_ASSERT_LOG)
-#define CHIP_ASSERT_LOG(aPrefix, aName, aCondition, aLabel, aFile, aLine, aMessage) \
- do \
- { \
- ChipLogError(NotSpecified, \
- CHIP_ASSERT_LOG_FORMAT_DEFAULT, \
- aPrefix, \
- (((aName) == 0) || (*(aName) == '\0')) ? "" : aName, \
- (((aName) == 0) || (*(aName) == '\0')) ? "" : ": ", \
- aCondition, \
- (((aMessage) == 0) ? "" : aMessage), \
- (((aMessage) == 0) ? "" : ", "), \
- aFile, \
- aLine); \
- } while (0)
-#endif
-// clang-format on
-
-/**
- * @} chip-specific nlassert.h Overrides
- *
- */
-
-#include <nlassert.h>
-
namespace chip {
// Generic min() and max() functions
@@ -157,328 +76,6 @@
#define IgnoreUnusedVariable(aVariable) ((void) (aVariable))
/**
- * @def ReturnErrorOnFailure(expr)
- *
- * @brief
- * Returns the error code if the expression returns something different
- * than CHIP_NO_ERROR.
- *
- * Example usage:
- *
- * @code
- * ReturnErrorOnFailure(channel->SendMsg(msg));
- * @endcode
- *
- * @param[in] expr A scalar expression to be evaluated against CHIP_NO_ERROR.
- */
-#define ReturnErrorOnFailure(expr) \
- do \
- { \
- CHIP_ERROR __err = (expr); \
- if (__err != CHIP_NO_ERROR) \
- { \
- return __err; \
- } \
- } while (false)
-
-/**
- * @def ReturnOnFailure(expr)
- *
- * @brief
- * Returns if the expression returns something different than CHIP_NO_ERROR
- *
- * Example usage:
- *
- * @code
- * ReturnOnFailure(channel->SendMsg(msg));
- * @endcode
- *
- * @param[in] expr A scalar expression to be evaluated against CHIP_NO_ERROR.
- */
-#define ReturnOnFailure(expr) \
- do \
- { \
- CHIP_ERROR __err = (expr); \
- if (__err != CHIP_NO_ERROR) \
- { \
- return; \
- } \
- } while (false)
-
-/**
- * @def VerifyOrReturn(expr, ...)
- *
- * @brief
- * Returns from the void function if expression evaluates to false
- *
- * Example usage:
- *
- * @code
- * VerifyOrReturn(param != nullptr, LogError("param is nullptr"));
- * @endcode
- *
- * @param[in] expr A Boolean expression to be evaluated.
- */
-#define VerifyOrReturn(expr, ...) \
- do \
- { \
- if (!(expr)) \
- { \
- __VA_ARGS__; \
- return; \
- } \
- } while (false)
-
-/**
- * @def VerifyOrReturnError(expr, code)
- *
- * @brief
- * Returns a specified error code if expression evaluates to false
- *
- * Example usage:
- *
- * @code
- * VerifyOrReturnError(param != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
- * @endcode
- *
- * @param[in] expr A Boolean expression to be evaluated.
- * @param[in] code A value to return if @a expr is false.
- */
-#define VerifyOrReturnError(expr, code) \
- do \
- { \
- if (!(expr)) \
- { \
- return code; \
- } \
- } while (false)
-
-/**
- * @def ReturnErrorCodeIf(expr, code)
- *
- * @brief
- * Returns a specified error code if expression evaluates to true
- *
- * Example usage:
- *
- * @code
- * ReturnErrorCodeIf(state == kInitialized, CHIP_NO_ERROR);
- * ReturnErrorCodeIf(state == kInitialized, CHIP_ERROR_INVALID_STATE);
- * @endcode
- *
- * @param[in] expr A Boolean expression to be evaluated.
- * @param[in] code A value to return if @a expr is false.
- */
-#define ReturnErrorCodeIf(expr, code) \
- do \
- { \
- if (expr) \
- { \
- return code; \
- } \
- } while (false)
-
-/**
- * @def SuccessOrExit(aStatus)
- *
- * @brief
- * This checks for the specified status, which is expected to
- * commonly be successful (CHIP_NO_ERROR), and branches to
- * the local label 'exit' if the status is unsuccessful.
- *
- * Example Usage:
- *
- * @code
- * CHIP_ERROR TryHard()
- * {
- * CHIP_ERROR err;
- *
- * err = TrySomething();
- * SuccessOrExit(err);
- *
- * err = TrySomethingElse();
- * SuccessOrExit(err);
- *
- * exit:
- * return err;
- * }
- * @endcode
- *
- * @param[in] aStatus A scalar status to be evaluated against zero (0).
- *
- */
-#define SuccessOrExit(aStatus) nlEXPECT((aStatus) == CHIP_NO_ERROR, exit)
-
-/**
- * @def VerifyOrExit(aCondition, anAction)
- *
- * @brief
- * This checks for the specified condition, which is expected to
- * commonly be true, and both executes @a anAction and branches to
- * the local label 'exit' if the condition is false.
- *
- * Example Usage:
- *
- * @code
- * CHIP_ERROR MakeBuffer(const uint8_t *& buf)
- * {
- * CHIP_ERROR err = CHIP_NO_ERROR;
- *
- * buf = (uint8_t *)malloc(1024);
- * VerifyOrExit(buf != NULL, err = CHIP_ERROR_NO_MEMORY);
- *
- * memset(buf, 0, 1024);
- *
- * exit:
- * return err;
- * }
- * @endcode
- *
- * @param[in] aCondition A Boolean expression to be evaluated.
- * @param[in] anAction An expression or block to execute when the
- * assertion fails.
- *
- */
-#define VerifyOrExit(aCondition, anAction) nlEXPECT_ACTION(aCondition, exit, anAction)
-
-/**
- * @def ExitNow(...)
- *
- * @brief
- * This unconditionally executes @a ... and branches to the local
- * label 'exit'.
- *
- * @note The use of this interface implies neither success nor
- * failure for the overall exit status of the enclosing function
- * body.
- *
- * Example Usage:
- *
- * @code
- * CHIP_ERROR ReadAll(Reader& reader)
- * {
- * CHIP_ERROR err;
- *
- * while (true)
- * {
- * err = reader.ReadNext();
- * if (err == CHIP_ERROR_AT_END)
- * ExitNow(err = CHIP_NO_ERROR);
- * SuccessOrExit(err);
- * DoSomething();
- * }
- *
- * exit:
- * return err;
- * }
- * @endcode
- *
- * @param[in] ... An optional expression or block to execute
- * when the assertion fails.
- *
- */
-// clang-format off
-#define ExitNow(...) \
- do { \
- __VA_ARGS__; \
- goto exit; \
- } while (0)
-// clang-format on
-
-/**
- * @brief
- * This is invoked when a #VerifyOrDie or #VerifyOrDieWithMsg
- * assertion expression evaluates to false.
- *
- * Developers may override and customize this by defining #chipDie
- * before CodeUtils.h is included by the preprocessor.
- *
- * Example Usage:
- *
- * @code
- * chipDie();
- * @endcode
- *
- */
-#ifndef chipDie
-extern "C" void chipDie(void) __attribute((noreturn));
-
-inline void chipDie(void)
-{
- ChipLogError(NotSpecified, "chipDie chipDie chipDie");
-
- while (true)
- {
- // CHIP_ASSERT_ABORT is redefined to be chipDie, so not useful here.
- abort();
- }
-}
-#endif // chipDie
-
-/**
- * @def VerifyOrDie(aCondition)
- *
- * @brief
- * This checks for the specified condition, which is expected to
- * commonly be true and forces an immediate abort if the condition
- * is false.
- *
- * Example Usage:
- *
- * @code
- * void FreeBuffer(const uint8_t *buf)
- * {
- * VerifyOrDie(buf != NULL);
- * free(buf);
- * }
- * @endcode
- *
- * @param[in] aCondition A Boolean expression to be evaluated.
- *
- * @sa #VerifyOrDieWithMsg
- * @sa #chipDie
- *
- */
-#define VerifyOrDie(aCondition) nlABORT(aCondition)
-
-/**
- * @def VerifyOrDieWithMsg(aCondition, aModule, aMessage, ...)
- *
- * @brief
- * This checks for the specified condition, which is expected to
- * commonly be true and both prints @a aMessage and forces an
- * immediate abort if the condition is false.
- *
- * Example Usage:
- *
- * @code
- * void FreeBuffer(const uint8_t *buf)
- * {
- * VerifyOrDieWithMsg(buf != NULL, MemoryManagement, "Invalid pointer passed to FreeBuffer");
- * free(buf);
- * }
- * @endcode
- *
- * @param[in] aCondition A Boolean expression to be evaluated.
- * @param[in] aModule A chip LogModule short-hand mnemonic identifing
- * the logical section of code that is a
- * source the logged message.
- * @param[in] aMessage A pointer to a NULL-terminated C string with
- * C Standard Library-style format specifiers
- * containing the log message to be formatted
- * and logged.
- * @param[in] ... A variadic argument list whose elements should
- * correspond to the format specifiers in @a
- * aMessage.
- *
- * @sa #VerifyOrDie
- * @sa #chipDie
- *
- */
-#define VerifyOrDieWithMsg(aCondition, aModule, aMessage, ...) \
- nlABORT_ACTION(aCondition, ChipLogDetail(aModule, aMessage, ##__VA_ARGS__))
-
-/**
* @def ArraySize(aArray)
*
* @brief
@@ -495,36 +92,6 @@
*/
#define ArraySize(a) (sizeof(a) / sizeof((a)[0]))
-#if defined(__cplusplus) && (__cplusplus >= 201103L)
-
-#ifndef __FINAL
-#define __FINAL final
-#endif
-
-#ifndef __OVERRIDE
-#define __OVERRIDE override
-#endif
-
-#ifndef __CONSTEXPR
-#define __CONSTEXPR constexpr
-#endif
-
-#else
-
-#ifndef __FINAL
-#define __FINAL
-#endif
-
-#ifndef __OVERRIDE
-#define __OVERRIDE
-#endif
-
-#ifndef __CONSTEXPR
-#define __CONSTEXPR constexpr
-#endif
-
-#endif // defined(__cplusplus) && (__cplusplus >= 201103L)
-
#if defined(__cplusplus) && \
((__cplusplus >= 201703L) || (defined(__GNUC__) && (__GNUC__ >= 7)) || (defined(__clang__)) && (__clang_major__ >= 4))
#define CHECK_RETURN_VALUE [[nodiscard]]
diff --git a/src/lib/support/DieMacros.h b/src/lib/support/DieMacros.h
new file mode 100644
index 0000000..5dd0b70
--- /dev/null
+++ b/src/lib/support/DieMacros.h
@@ -0,0 +1,200 @@
+/*
+ *
+ * Copyright (c) 2020-2021 Project CHIP Authors
+ * Copyright (c) 2013-2017 Nest Labs, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <support/DieMacros.h>
+#include <support/logging/CHIPLogging.h>
+
+/**
+ * @name chip-specific nlassert.h Overrides
+ *
+ * @{
+ *
+ */
+
+/**
+ * @def CHIP_ASSERT_ABORT()
+ *
+ * @brief
+ * This implements a chip-specific override for #CHIP_ASSERT_ABORT *
+ * from nlassert.h.
+ *
+ */
+#if !defined(CHIP_ASSERT_ABORT)
+#define CHIP_ASSERT_ABORT() chipDie()
+#endif
+
+/**
+ * @def CHIP_ASSERT_LOG(aPrefix, aName, aCondition, aLabel, aFile, aLine, aMessage)
+ *
+ * @brief
+ * This implements a chip-specific override for \c CHIP_ASSERT_LOG
+ * from nlassert.h.
+ *
+ * @param[in] aPrefix A pointer to a NULL-terminated C string printed
+ * at the beginning of the logged assertion
+ * message. Typically this is and should be
+ * \c CHIP_ASSERT_PREFIX_STRING.
+ * @param[in] aName A pointer to a NULL-terminated C string printed
+ * following @a aPrefix that indicates what
+ * module, program, application or subsystem
+ * the assertion occurred in Typically this
+ * is and should be
+ * \c CHIP_ASSERT_COMPONENT_STRING.
+ * @param[in] aCondition A pointer to a NULL-terminated C string indicating
+ * the expression that evaluated to false in
+ * the assertion. Typically this is a
+ * stringified version of the actual
+ * assertion expression.
+ * @param[in] aLabel An optional pointer to a NULL-terminated C string
+ * indicating, for exception-style
+ * assertions, the label that will be
+ * branched to when the assertion expression
+ * evaluates to false.
+ * @param[in] aFile A pointer to a NULL-terminated C string indicating
+ * the file in which the exception
+ * occurred. Typically this is and should be
+ * \_\_FILE\_\_ from the C preprocessor.
+ * @param[in] aLine The line number in @a aFile on which the assertion
+ * expression evaluated to false. Typically
+ * this is and should be \_\_LINE\_\_ from the C
+ * preprocessor.
+ * @param[in] aMessage An optional pointer to a NULL-terminated C string
+ * containing a caller-specified message
+ * further describing the assertion failure.
+ *
+ */
+// clang-format off
+#if !defined(CHIP_ASSERT_LOG)
+#define CHIP_ASSERT_LOG(aPrefix, aName, aCondition, aLabel, aFile, aLine, aMessage) \
+ do \
+ { \
+ ChipLogError(NotSpecified, \
+ CHIP_ASSERT_LOG_FORMAT_DEFAULT, \
+ aPrefix, \
+ (((aName) == 0) || (*(aName) == '\0')) ? "" : aName, \
+ (((aName) == 0) || (*(aName) == '\0')) ? "" : ": ", \
+ aCondition, \
+ (((aMessage) == 0) ? "" : aMessage), \
+ (((aMessage) == 0) ? "" : ", "), \
+ aFile, \
+ aLine); \
+ } while (0)
+#endif
+// clang-format on
+
+/**
+ * @} chip-specific nlassert.h Overrides
+ *
+ */
+
+#include <nlassert.h>
+
+/**
+ * @brief
+ * This is invoked when a #VerifyOrDie or #VerifyOrDieWithMsg
+ * assertion expression evaluates to false.
+ *
+ * Developers may override and customize this by defining #chipDie
+ * before CodeUtils.h is included by the preprocessor.
+ *
+ * Example Usage:
+ *
+ * @code
+ * chipDie();
+ * @endcode
+ *
+ */
+#ifndef chipDie
+extern "C" void chipDie(void) __attribute((noreturn));
+
+inline void chipDie(void)
+{
+ ChipLogError(NotSpecified, "chipDie chipDie chipDie");
+
+ while (true)
+ {
+ // CHIP_ASSERT_ABORT is redefined to be chipDie, so not useful here.
+ abort();
+ }
+}
+#endif // chipDie
+
+/**
+ * @def VerifyOrDie(aCondition)
+ *
+ * @brief
+ * This checks for the specified condition, which is expected to
+ * commonly be true and forces an immediate abort if the condition
+ * is false.
+ *
+ * Example Usage:
+ *
+ * @code
+ * void FreeBuffer(const uint8_t *buf)
+ * {
+ * VerifyOrDie(buf != NULL);
+ * free(buf);
+ * }
+ * @endcode
+ *
+ * @param[in] aCondition A Boolean expression to be evaluated.
+ *
+ * @sa #VerifyOrDieWithMsg
+ * @sa #chipDie
+ *
+ */
+#define VerifyOrDie(aCondition) nlABORT(aCondition)
+
+/**
+ * @def VerifyOrDieWithMsg(aCondition, aModule, aMessage, ...)
+ *
+ * @brief
+ * This checks for the specified condition, which is expected to
+ * commonly be true and both prints @a aMessage and forces an
+ * immediate abort if the condition is false.
+ *
+ * Example Usage:
+ *
+ * @code
+ * void FreeBuffer(const uint8_t *buf)
+ * {
+ * VerifyOrDieWithMsg(buf != NULL, MemoryManagement, "Invalid pointer passed to FreeBuffer");
+ * free(buf);
+ * }
+ * @endcode
+ *
+ * @param[in] aCondition A Boolean expression to be evaluated.
+ * @param[in] aModule A chip LogModule short-hand mnemonic identifing
+ * the logical section of code that is a
+ * source the logged message.
+ * @param[in] aMessage A pointer to a NULL-terminated C string with
+ * C Standard Library-style format specifiers
+ * containing the log message to be formatted
+ * and logged.
+ * @param[in] ... A variadic argument list whose elements should
+ * correspond to the format specifiers in @a
+ * aMessage.
+ *
+ * @sa #VerifyOrDie
+ * @sa #chipDie
+ *
+ */
+#define VerifyOrDieWithMsg(aCondition, aModule, aMessage, ...) \
+ nlABORT_ACTION(aCondition, ChipLogDetail(aModule, aMessage, ##__VA_ARGS__))
diff --git a/src/lib/support/ErrorMacros.h b/src/lib/support/ErrorMacros.h
new file mode 100644
index 0000000..9000499
--- /dev/null
+++ b/src/lib/support/ErrorMacros.h
@@ -0,0 +1,130 @@
+/*
+ *
+ * Copyright (c) 2020-2021 Project CHIP Authors
+ * Copyright (c) 2013-2017 Nest Labs, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <nlassert.h>
+
+#include <core/CHIPError.h>
+
+/**
+ * @def SuccessOrExit(aStatus)
+ *
+ * @brief
+ * This checks for the specified status, which is expected to
+ * commonly be successful (CHIP_NO_ERROR), and branches to
+ * the local label 'exit' if the status is unsuccessful.
+ *
+ * Example Usage:
+ *
+ * @code
+ * CHIP_ERROR TryHard()
+ * {
+ * CHIP_ERROR err;
+ *
+ * err = TrySomething();
+ * SuccessOrExit(err);
+ *
+ * err = TrySomethingElse();
+ * SuccessOrExit(err);
+ *
+ * exit:
+ * return err;
+ * }
+ * @endcode
+ *
+ * @param[in] aStatus A scalar status to be evaluated against zero (0).
+ *
+ */
+#define SuccessOrExit(aStatus) nlEXPECT((aStatus) == CHIP_NO_ERROR, exit)
+
+/**
+ * @def VerifyOrExit(aCondition, anAction)
+ *
+ * @brief
+ * This checks for the specified condition, which is expected to
+ * commonly be true, and both executes @a anAction and branches to
+ * the local label 'exit' if the condition is false.
+ *
+ * Example Usage:
+ *
+ * @code
+ * CHIP_ERROR MakeBuffer(const uint8_t *& buf)
+ * {
+ * CHIP_ERROR err = CHIP_NO_ERROR;
+ *
+ * buf = (uint8_t *)malloc(1024);
+ * VerifyOrExit(buf != NULL, err = CHIP_ERROR_NO_MEMORY);
+ *
+ * memset(buf, 0, 1024);
+ *
+ * exit:
+ * return err;
+ * }
+ * @endcode
+ *
+ * @param[in] aCondition A Boolean expression to be evaluated.
+ * @param[in] anAction An expression or block to execute when the
+ * assertion fails.
+ *
+ */
+#define VerifyOrExit(aCondition, anAction) nlEXPECT_ACTION(aCondition, exit, anAction)
+
+/**
+ * @def ExitNow(...)
+ *
+ * @brief
+ * This unconditionally executes @a ... and branches to the local
+ * label 'exit'.
+ *
+ * @note The use of this interface implies neither success nor
+ * failure for the overall exit status of the enclosing function
+ * body.
+ *
+ * Example Usage:
+ *
+ * @code
+ * CHIP_ERROR ReadAll(Reader& reader)
+ * {
+ * CHIP_ERROR err;
+ *
+ * while (true)
+ * {
+ * err = reader.ReadNext();
+ * if (err == CHIP_ERROR_AT_END)
+ * ExitNow(err = CHIP_NO_ERROR);
+ * SuccessOrExit(err);
+ * DoSomething();
+ * }
+ *
+ * exit:
+ * return err;
+ * }
+ * @endcode
+ *
+ * @param[in] ... An optional expression or block to execute
+ * when the assertion fails.
+ *
+ */
+// clang-format off
+#define ExitNow(...) \
+ do { \
+ __VA_ARGS__; \
+ goto exit; \
+ } while (0)
+// clang-format on
diff --git a/src/lib/support/ErrorStr.cpp b/src/lib/support/ErrorStr.cpp
index f6cee46..eff4131 100644
--- a/src/lib/support/ErrorStr.cpp
+++ b/src/lib/support/ErrorStr.cpp
@@ -31,7 +31,7 @@
#include <stdio.h>
#include <core/CHIPCore.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorStr.h>
namespace chip {
diff --git a/src/lib/support/LifetimePersistedCounter.cpp b/src/lib/support/LifetimePersistedCounter.cpp
index 3ac866d..2efe8d2 100644
--- a/src/lib/support/LifetimePersistedCounter.cpp
+++ b/src/lib/support/LifetimePersistedCounter.cpp
@@ -18,7 +18,7 @@
#include "LifetimePersistedCounter.h"
#include <platform/PersistedStorage.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <stdlib.h>
diff --git a/src/lib/support/PersistedCounter.cpp b/src/lib/support/PersistedCounter.cpp
index 1f8ba57..2c6f86e 100644
--- a/src/lib/support/PersistedCounter.cpp
+++ b/src/lib/support/PersistedCounter.cpp
@@ -19,7 +19,7 @@
#include "PersistedCounter.h"
#include <platform/PersistedStorage.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <stdlib.h>
diff --git a/src/lib/support/PrivateHeap.cpp b/src/lib/support/PrivateHeap.cpp
index e906792..a45374b 100644
--- a/src/lib/support/PrivateHeap.cpp
+++ b/src/lib/support/PrivateHeap.cpp
@@ -18,7 +18,7 @@
#include "PrivateHeap.h"
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
#include <support/logging/CHIPLogging.h>
namespace {
diff --git a/src/lib/support/ReturnMacros.h b/src/lib/support/ReturnMacros.h
new file mode 100644
index 0000000..8ab58f7
--- /dev/null
+++ b/src/lib/support/ReturnMacros.h
@@ -0,0 +1,90 @@
+/*
+ *
+ * Copyright (c) 2020 Project CHIP Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <core/CHIPError.h>
+
+/// Returns the error code if the expression returns something different
+/// than CHIP_NO_ERROR
+///
+/// Use like:
+/// ReturnErrorOnFailure(channel->SendMsg(msg));
+#define ReturnErrorOnFailure(expr) \
+ do \
+ { \
+ CHIP_ERROR __err = (expr); \
+ if (__err != CHIP_NO_ERROR) \
+ { \
+ return __err; \
+ } \
+ } while (false)
+
+/// Returns if the expression returns something different than CHIP_NO_ERROR
+///
+/// Use like:
+/// ReturnOnFailure(channel->SendMsg(msg));
+#define ReturnOnFailure(expr) \
+ do \
+ { \
+ CHIP_ERROR __err = (expr); \
+ if (__err != CHIP_NO_ERROR) \
+ { \
+ return; \
+ } \
+ } while (false)
+
+/// Returns from the void function if expression evaluates to false
+///
+/// Use like:
+/// VerifyOrReturn(param != nullptr, LogError("param is nullptr"));
+#define VerifyOrReturn(expr, ...) \
+ do \
+ { \
+ if (!(expr)) \
+ { \
+ __VA_ARGS__; \
+ return; \
+ } \
+ } while (false)
+
+/// Returns a specified error code if expression evaluates to false
+///
+/// Use like:
+/// VerifyOrReturnError(param != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
+#define VerifyOrReturnError(expr, code) \
+ do \
+ { \
+ if (!(expr)) \
+ { \
+ return code; \
+ } \
+ } while (false)
+
+/// Returns a specified error code if expression evaluates to true
+///
+/// Use like:
+/// ReturnErrorCodeIf(state == kInitialized, CHIP_NO_ERROR);
+/// ReturnErrorCodeIf(state == kInitialized, CHIP_ERROR_INVALID_STATE);
+#define ReturnErrorCodeIf(expr, code) \
+ do \
+ { \
+ if (expr) \
+ { \
+ return code; \
+ } \
+ } while (false)
diff --git a/src/lib/support/SafeString.h b/src/lib/support/SafeString.h
index 6fe1038..d25a097 100644
--- a/src/lib/support/SafeString.h
+++ b/src/lib/support/SafeString.h
@@ -23,9 +23,11 @@
#pragma once
-#include <support/CodeUtils.h>
+#include <cstddef>
#include <utility>
+#include <support/CodeUtils.h>
+
namespace chip {
/**
diff --git a/src/lib/support/SerializableIntegerSet.cpp b/src/lib/support/SerializableIntegerSet.cpp
index b1c1ecd..532868e 100644
--- a/src/lib/support/SerializableIntegerSet.cpp
+++ b/src/lib/support/SerializableIntegerSet.cpp
@@ -19,6 +19,7 @@
#include "SerializableIntegerSet.h"
#include <core/CHIPEncoding.h>
+#include <support/ErrorMacros.h>
namespace chip {
diff --git a/src/lib/support/SerializableIntegerSet.h b/src/lib/support/SerializableIntegerSet.h
index 7212955..29ac202 100644
--- a/src/lib/support/SerializableIntegerSet.h
+++ b/src/lib/support/SerializableIntegerSet.h
@@ -31,8 +31,10 @@
#pragma once
+#include <nlassert.h>
+
+#include <core/CHIPError.h>
#include <support/Base64.h>
-#include <support/CodeUtils.h>
// BASE64_ENCODED_LEN doesn't account for null termination of the string.
// So, we are adding 1 extra byte to the size requirement.
diff --git a/src/lib/support/TimeUtils.cpp b/src/lib/support/TimeUtils.cpp
index c28ce6d..19278c8 100644
--- a/src/lib/support/TimeUtils.cpp
+++ b/src/lib/support/TimeUtils.cpp
@@ -31,6 +31,7 @@
#include <type_traits>
#include <core/CHIPCore.h>
+#include <support/ErrorMacros.h>
#include <support/SafeInt.h>
#include "TimeUtils.h"
diff --git a/src/lib/support/UnitTestRegistration.h b/src/lib/support/UnitTestRegistration.h
index 41d634c..5c7a205 100644
--- a/src/lib/support/UnitTestRegistration.h
+++ b/src/lib/support/UnitTestRegistration.h
@@ -18,7 +18,7 @@
#pragma once
#include <core/CHIPError.h>
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
/**
* @def CHIP_REGISTER_TEST_SUITE(FUNCTION)
diff --git a/src/lib/support/logging/CHIPLogging.cpp b/src/lib/support/logging/CHIPLogging.cpp
index 3bf3164..5895253 100644
--- a/src/lib/support/logging/CHIPLogging.cpp
+++ b/src/lib/support/logging/CHIPLogging.cpp
@@ -26,7 +26,6 @@
#include "CHIPLogging.h"
#include <core/CHIPCore.h>
-#include <support/CodeUtils.h>
#include <support/DLLUtil.h>
#include <stdarg.h>
diff --git a/src/lib/support/logging/CHIPLogging.h b/src/lib/support/logging/CHIPLogging.h
index 97bf5e9..948a1d0 100644
--- a/src/lib/support/logging/CHIPLogging.h
+++ b/src/lib/support/logging/CHIPLogging.h
@@ -35,9 +35,11 @@
#pragma once
#include <core/CHIPConfig.h>
+#include <support/ErrorStr.h>
#include <platform/logging/LogV.h>
+#include <support/ErrorStr.h>
#include <support/logging/Constants.h>
#include <stdarg.h>
diff --git a/src/lib/support/tests/TestCHIPMem.cpp b/src/lib/support/tests/TestCHIPMem.cpp
index 613f386..7537e30 100644
--- a/src/lib/support/tests/TestCHIPMem.cpp
+++ b/src/lib/support/tests/TestCHIPMem.cpp
@@ -31,7 +31,6 @@
#include <nlunit-test.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <support/UnitTestRegistration.h>
using namespace chip;
diff --git a/src/lib/support/tests/TestPersistedStorageImplementation.cpp b/src/lib/support/tests/TestPersistedStorageImplementation.cpp
index bedae43..6bd1d2c 100644
--- a/src/lib/support/tests/TestPersistedStorageImplementation.cpp
+++ b/src/lib/support/tests/TestPersistedStorageImplementation.cpp
@@ -38,7 +38,7 @@
#include <platform/PersistedStorage.h>
#include <support/Base64.h>
#include <support/CHIPArgParser.hpp>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include "TestPersistedStorageImplementation.h"
diff --git a/src/messaging/ExchangeACL.h b/src/messaging/ExchangeACL.h
index 358485c..ce34db7 100644
--- a/src/messaging/ExchangeACL.h
+++ b/src/messaging/ExchangeACL.h
@@ -18,6 +18,7 @@
#pragma once
#include <app/util/basic-types.h>
+#include <support/ReturnMacros.h>
#include <transport/AdminPairingTable.h>
namespace chip {
diff --git a/src/messaging/ExchangeContext.cpp b/src/messaging/ExchangeContext.cpp
index 1968fcd..c308c59 100644
--- a/src/messaging/ExchangeContext.cpp
+++ b/src/messaging/ExchangeContext.cpp
@@ -39,6 +39,9 @@
#include <messaging/ExchangeMgr.h>
#include <protocols/Protocols.h>
#include <protocols/secure_channel/Constants.h>
+#include <support/DieMacros.h>
+#include <support/ErrorMacros.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
#include <system/SystemTimer.h>
diff --git a/src/messaging/ExchangeMgr.cpp b/src/messaging/ExchangeMgr.cpp
index 301a108..af52afd 100644
--- a/src/messaging/ExchangeMgr.cpp
+++ b/src/messaging/ExchangeMgr.cpp
@@ -39,8 +39,10 @@
#include <messaging/ExchangeMgr.h>
#include <protocols/Protocols.h>
#include <support/CHIPFaultInjection.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
#include <support/RandUtils.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
using namespace chip::Encoding;
diff --git a/src/messaging/MessageCounterSync.cpp b/src/messaging/MessageCounterSync.cpp
index 341b23b..a4ca0ef 100644
--- a/src/messaging/MessageCounterSync.cpp
+++ b/src/messaging/MessageCounterSync.cpp
@@ -30,7 +30,9 @@
#include <messaging/MessageCounterSync.h>
#include <protocols/Protocols.h>
#include <support/BufferWriter.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
namespace chip {
diff --git a/src/messaging/ReliableMessageContext.cpp b/src/messaging/ReliableMessageContext.cpp
index d1cefb9..c7df0c9 100644
--- a/src/messaging/ReliableMessageContext.cpp
+++ b/src/messaging/ReliableMessageContext.cpp
@@ -32,7 +32,7 @@
#include <messaging/ReliableMessageMgr.h>
#include <protocols/Protocols.h>
#include <protocols/secure_channel/Constants.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
namespace chip {
namespace Messaging {
diff --git a/src/messaging/ReliableMessageMgr.cpp b/src/messaging/ReliableMessageMgr.cpp
index 05fd0d6..7987acb 100644
--- a/src/messaging/ReliableMessageMgr.cpp
+++ b/src/messaging/ReliableMessageMgr.cpp
@@ -30,7 +30,7 @@
#include <messaging/ReliableMessageContext.h>
#include <support/BitFlags.h>
#include <support/CHIPFaultInjection.h>
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
#include <support/logging/CHIPLogging.h>
namespace chip {
diff --git a/src/messaging/tests/MessagingContext.cpp b/src/messaging/tests/MessagingContext.cpp
index b4450de..edaee07 100644
--- a/src/messaging/tests/MessagingContext.cpp
+++ b/src/messaging/tests/MessagingContext.cpp
@@ -17,8 +17,8 @@
#include <messaging/tests/MessagingContext.h>
-#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
namespace chip {
namespace Test {
diff --git a/src/messaging/tests/TestChannel.cpp b/src/messaging/tests/TestChannel.cpp
index 3b456c7..8859098 100644
--- a/src/messaging/tests/TestChannel.cpp
+++ b/src/messaging/tests/TestChannel.cpp
@@ -30,7 +30,6 @@
#include <messaging/tests/MessagingContext.h>
#include <protocols/Protocols.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <transport/SecureSessionMgr.h>
#include <transport/TransportMgr.h>
diff --git a/src/messaging/tests/TestExchangeMgr.cpp b/src/messaging/tests/TestExchangeMgr.cpp
index 9e181e8..16ee629 100644
--- a/src/messaging/tests/TestExchangeMgr.cpp
+++ b/src/messaging/tests/TestExchangeMgr.cpp
@@ -30,7 +30,6 @@
#include <messaging/tests/MessagingContext.h>
#include <protocols/Protocols.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <transport/SecureSessionMgr.h>
#include <transport/TransportMgr.h>
diff --git a/src/messaging/tests/TestMessageCounterSyncMgr.cpp b/src/messaging/tests/TestMessageCounterSyncMgr.cpp
index 614a1e5..147f759 100644
--- a/src/messaging/tests/TestMessageCounterSyncMgr.cpp
+++ b/src/messaging/tests/TestMessageCounterSyncMgr.cpp
@@ -28,7 +28,7 @@
#include <messaging/ReliableMessageMgr.h>
#include <protocols/Protocols.h>
#include <protocols/echo/Echo.h>
-#include <support/CodeUtils.h>
+#include <support/ReturnMacros.h>
#include <transport/SecureSessionMgr.h>
#include <transport/TransportMgr.h>
diff --git a/src/messaging/tests/TestReliableMessageProtocol.cpp b/src/messaging/tests/TestReliableMessageProtocol.cpp
index 213f92b..b9a361b 100644
--- a/src/messaging/tests/TestReliableMessageProtocol.cpp
+++ b/src/messaging/tests/TestReliableMessageProtocol.cpp
@@ -29,7 +29,7 @@
#include <messaging/ReliableMessageMgr.h>
#include <protocols/Protocols.h>
#include <protocols/echo/Echo.h>
-#include <support/CodeUtils.h>
+#include <support/ReturnMacros.h>
#include <transport/SecureSessionMgr.h>
#include <transport/TransportMgr.h>
diff --git a/src/messaging/tests/echo/common.cpp b/src/messaging/tests/echo/common.cpp
index dc5dd52..93dafa8 100644
--- a/src/messaging/tests/echo/common.cpp
+++ b/src/messaging/tests/echo/common.cpp
@@ -27,6 +27,7 @@
#include "common.h"
#include <core/CHIPCore.h>
#include <platform/CHIPDeviceLayer.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
// The ExchangeManager global object.
diff --git a/src/messaging/tests/echo/echo_requester.cpp b/src/messaging/tests/echo/echo_requester.cpp
index f8eecbb..646e9f7 100644
--- a/src/messaging/tests/echo/echo_requester.cpp
+++ b/src/messaging/tests/echo/echo_requester.cpp
@@ -32,6 +32,7 @@
#include <core/CHIPCore.h>
#include <platform/CHIPDeviceLayer.h>
#include <protocols/echo/Echo.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
#include <system/SystemPacketBuffer.h>
#include <transport/PASESession.h>
diff --git a/src/messaging/tests/echo/echo_responder.cpp b/src/messaging/tests/echo/echo_responder.cpp
index 2a44aa3..4cdb68a 100644
--- a/src/messaging/tests/echo/echo_responder.cpp
+++ b/src/messaging/tests/echo/echo_responder.cpp
@@ -32,6 +32,7 @@
#include <core/CHIPCore.h>
#include <platform/CHIPDeviceLayer.h>
#include <protocols/echo/Echo.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
#include <system/SystemPacketBuffer.h>
#include <transport/PASESession.h>
diff --git a/src/platform/Darwin/ConfigurationManagerImpl.cpp b/src/platform/Darwin/ConfigurationManagerImpl.cpp
index 310a9e5..b875134 100644
--- a/src/platform/Darwin/ConfigurationManagerImpl.cpp
+++ b/src/platform/Darwin/ConfigurationManagerImpl.cpp
@@ -30,7 +30,7 @@
#include <platform/Darwin/PosixConfig.h>
#include <platform/internal/GenericConfigurationManagerImpl.cpp>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
namespace chip {
diff --git a/src/platform/Darwin/ConnectivityManagerImpl.cpp b/src/platform/Darwin/ConnectivityManagerImpl.cpp
index b5d073c..1abdaad 100644
--- a/src/platform/Darwin/ConnectivityManagerImpl.cpp
+++ b/src/platform/Darwin/ConnectivityManagerImpl.cpp
@@ -23,7 +23,7 @@
#include <new>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
diff --git a/src/platform/Darwin/PosixConfig.cpp b/src/platform/Darwin/PosixConfig.cpp
index 4c08ba9..8b84704 100644
--- a/src/platform/Darwin/PosixConfig.cpp
+++ b/src/platform/Darwin/PosixConfig.cpp
@@ -29,7 +29,7 @@
#include <core/CHIPEncoding.h>
#include <platform/Darwin/PosixConfig.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
namespace chip {
namespace DeviceLayer {
diff --git a/src/platform/EFR32/BLEManagerImpl.cpp b/src/platform/EFR32/BLEManagerImpl.cpp
index b34a4ad..d87aa59 100644
--- a/src/platform/EFR32/BLEManagerImpl.cpp
+++ b/src/platform/EFR32/BLEManagerImpl.cpp
@@ -35,7 +35,8 @@
#include "timers.h"
#include <ble/CHIPBleServiceData.h>
#include <platform/EFR32/freertos_bluetooth.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
#include <support/logging/CHIPLogging.h>
using namespace ::chip;
diff --git a/src/platform/EFR32/ConfigurationManagerImpl.cpp b/src/platform/EFR32/ConfigurationManagerImpl.cpp
index 8b26e71..64fd13c 100644
--- a/src/platform/EFR32/ConfigurationManagerImpl.cpp
+++ b/src/platform/EFR32/ConfigurationManagerImpl.cpp
@@ -28,6 +28,8 @@
#include <platform/ConfigurationManager.h>
#include <platform/EFR32/EFR32Config.h>
+#include <support/ErrorStr.h>
+#include <support/logging/CHIPLogging.h>
namespace chip {
namespace DeviceLayer {
diff --git a/src/platform/EFR32/ConnectivityManagerImpl.cpp b/src/platform/EFR32/ConnectivityManagerImpl.cpp
index ffb0ba6..a16ef48 100644
--- a/src/platform/EFR32/ConnectivityManagerImpl.cpp
+++ b/src/platform/EFR32/ConnectivityManagerImpl.cpp
@@ -20,7 +20,7 @@
#include <platform/ConnectivityManager.h>
#include <platform/internal/BLEManager.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <lwip/dns.h>
diff --git a/src/platform/EFR32/DeviceNetworkProvisioningDelegateImpl.cpp b/src/platform/EFR32/DeviceNetworkProvisioningDelegateImpl.cpp
index 4a75640..648930c 100644
--- a/src/platform/EFR32/DeviceNetworkProvisioningDelegateImpl.cpp
+++ b/src/platform/EFR32/DeviceNetworkProvisioningDelegateImpl.cpp
@@ -19,6 +19,7 @@
#if CHIP_ENABLE_OPENTHREAD
#include <platform/ThreadStackManager.h>
+#include <support/ErrorMacros.h>
#endif
namespace chip {
diff --git a/src/platform/EFR32/EFR32Config.cpp b/src/platform/EFR32/EFR32Config.cpp
index 1437403..d7f4b3a 100644
--- a/src/platform/EFR32/EFR32Config.cpp
+++ b/src/platform/EFR32/EFR32Config.cpp
@@ -28,6 +28,7 @@
#include <core/CHIPEncoding.h>
#include <platform/internal/testing/ConfigUnitTest.h>
+#include <support/ErrorMacros.h>
#include "FreeRTOS.h"
#include "nvm3.h"
diff --git a/src/platform/EFR32/Entropy.cpp b/src/platform/EFR32/Entropy.cpp
index 40b9697..0a74766 100644
--- a/src/platform/EFR32/Entropy.cpp
+++ b/src/platform/EFR32/Entropy.cpp
@@ -24,6 +24,8 @@
/* this file behaves like a config.h, comes first */
#include <platform/internal/CHIPDeviceLayerInternal.h>
+#include <support/DieMacros.h>
+#include <support/ErrorMacros.h>
#include <support/crypto/CHIPRNG.h>
#include <mbedtls/entropy_poll.h>
diff --git a/src/platform/EFR32/ThreadStackManagerImpl.cpp b/src/platform/EFR32/ThreadStackManagerImpl.cpp
index 66edcea..fd46d4f 100644
--- a/src/platform/EFR32/ThreadStackManagerImpl.cpp
+++ b/src/platform/EFR32/ThreadStackManagerImpl.cpp
@@ -35,6 +35,7 @@
#include <openthread/platform/entropy.h>
#include <support/CHIPPlatformMemory.h>
+#include <support/ErrorMacros.h>
namespace chip {
namespace DeviceLayer {
diff --git a/src/platform/ESP32/ConfigurationManagerImpl.cpp b/src/platform/ESP32/ConfigurationManagerImpl.cpp
index 2008bfc..4bfc673 100644
--- a/src/platform/ESP32/ConfigurationManagerImpl.cpp
+++ b/src/platform/ESP32/ConfigurationManagerImpl.cpp
@@ -29,7 +29,7 @@
#include <platform/ConfigurationManager.h>
#include <platform/ESP32/ESP32Config.h>
#include <platform/internal/GenericConfigurationManagerImpl.cpp>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include "esp_wifi.h"
#include "nvs.h"
diff --git a/src/platform/ESP32/ConnectivityManagerImpl.cpp b/src/platform/ESP32/ConnectivityManagerImpl.cpp
index 2f3e97c..d0ea05e 100644
--- a/src/platform/ESP32/ConnectivityManagerImpl.cpp
+++ b/src/platform/ESP32/ConnectivityManagerImpl.cpp
@@ -27,7 +27,7 @@
#include <platform/ESP32/ESP32Utils.h>
#include <platform/internal/BLEManager.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include "esp_event.h"
diff --git a/src/platform/ESP32/ESP32Config.cpp b/src/platform/ESP32/ESP32Config.cpp
index 1063d56..a4f3457 100644
--- a/src/platform/ESP32/ESP32Config.cpp
+++ b/src/platform/ESP32/ESP32Config.cpp
@@ -31,7 +31,7 @@
#include <platform/ESP32/ESP32Utils.h>
#include <support/CHIPMem.h>
#include <support/CHIPMemString.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include "nvs.h"
diff --git a/src/platform/ESP32/ESP32Utils.cpp b/src/platform/ESP32/ESP32Utils.cpp
index d64149a..551f56c 100644
--- a/src/platform/ESP32/ESP32Utils.cpp
+++ b/src/platform/ESP32/ESP32Utils.cpp
@@ -25,7 +25,7 @@
#include <platform/internal/CHIPDeviceLayerInternal.h>
#include <platform/ESP32/ESP32Utils.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
#include <support/logging/CHIPLogging.h>
diff --git a/src/platform/ESP32/Entropy.cpp b/src/platform/ESP32/Entropy.cpp
index 17ffb57..af6f33b 100644
--- a/src/platform/ESP32/Entropy.cpp
+++ b/src/platform/ESP32/Entropy.cpp
@@ -25,6 +25,7 @@
/* this file behaves like a config.h, comes first */
#include <platform/internal/CHIPDeviceLayerInternal.h>
+#include <support/ErrorMacros.h>
#include <support/crypto/CHIPRNG.h>
#include "esp_log.h"
diff --git a/src/platform/ESP32/KeyValueStoreManagerImpl.cpp b/src/platform/ESP32/KeyValueStoreManagerImpl.cpp
index f892169..d670978 100644
--- a/src/platform/ESP32/KeyValueStoreManagerImpl.cpp
+++ b/src/platform/ESP32/KeyValueStoreManagerImpl.cpp
@@ -28,7 +28,7 @@
#include "nvs.h"
#include "nvs_flash.h"
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
namespace chip {
namespace DeviceLayer {
diff --git a/src/platform/ESP32/MdnsImpl.cpp b/src/platform/ESP32/MdnsImpl.cpp
index cafb7aa..ab96aa0 100644
--- a/src/platform/ESP32/MdnsImpl.cpp
+++ b/src/platform/ESP32/MdnsImpl.cpp
@@ -24,7 +24,7 @@
#include "platform/CHIPDeviceLayer.h"
#include "support/CHIPMem.h"
-#include "support/CodeUtils.h"
+#include "support/ErrorMacros.h"
#include "support/logging/CHIPLogging.h"
namespace {
diff --git a/src/platform/ESP32/ServiceProvisioning.cpp b/src/platform/ESP32/ServiceProvisioning.cpp
index 925f4cf..00cc207 100644
--- a/src/platform/ESP32/ServiceProvisioning.cpp
+++ b/src/platform/ESP32/ServiceProvisioning.cpp
@@ -16,7 +16,7 @@
*/
#include <platform/CHIPDeviceLayer.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <algorithm>
diff --git a/src/platform/ESP32/bluedroid/BLEManagerImpl.cpp b/src/platform/ESP32/bluedroid/BLEManagerImpl.cpp
index 47cd465..d059bd7 100644
--- a/src/platform/ESP32/bluedroid/BLEManagerImpl.cpp
+++ b/src/platform/ESP32/bluedroid/BLEManagerImpl.cpp
@@ -33,7 +33,7 @@
#include <ble/CHIPBleServiceData.h>
#include <platform/internal/BLEManager.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include "esp_bt.h"
diff --git a/src/platform/ESP32/nimble/BLEManagerImpl.cpp b/src/platform/ESP32/nimble/BLEManagerImpl.cpp
index 904528b..34c2194 100644
--- a/src/platform/ESP32/nimble/BLEManagerImpl.cpp
+++ b/src/platform/ESP32/nimble/BLEManagerImpl.cpp
@@ -32,7 +32,7 @@
#include <ble/CHIPBleServiceData.h>
#include <platform/internal/BLEManager.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <system/SystemTimer.h>
diff --git a/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.cpp b/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.cpp
index 950d755..56dc13b 100644
--- a/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.cpp
+++ b/src/platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.cpp
@@ -30,7 +30,8 @@
#include <platform/OpenThread/OpenThreadUtils.h>
#include <platform/ThreadStackManager.h>
#include <platform/internal/CHIPDeviceLayerInternal.h>
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
namespace chip {
diff --git a/src/platform/GeneralUtils.cpp b/src/platform/GeneralUtils.cpp
index 56e1103..6819ed7 100644
--- a/src/platform/GeneralUtils.cpp
+++ b/src/platform/GeneralUtils.cpp
@@ -23,7 +23,8 @@
*/
#include <platform/internal/CHIPDeviceLayerInternal.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
namespace chip {
namespace DeviceLayer {
diff --git a/src/platform/K32W/BLEManagerImpl.cpp b/src/platform/K32W/BLEManagerImpl.cpp
index 1613044..917ea1a 100644
--- a/src/platform/K32W/BLEManagerImpl.cpp
+++ b/src/platform/K32W/BLEManagerImpl.cpp
@@ -27,6 +27,8 @@
#include <platform/internal/CHIPDeviceLayerInternal.h>
#include <crypto/CHIPCryptoPAL.h>
+#include <support/ErrorStr.h>
+#include <support/logging/CHIPLogging.h>
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
diff --git a/src/platform/K32W/ConfigurationManagerImpl.cpp b/src/platform/K32W/ConfigurationManagerImpl.cpp
index c50a407..0ee9bf6 100644
--- a/src/platform/K32W/ConfigurationManagerImpl.cpp
+++ b/src/platform/K32W/ConfigurationManagerImpl.cpp
@@ -29,6 +29,8 @@
#include <platform/ConfigurationManager.h>
#include <platform/K32W/K32WConfig.h>
#include <platform/internal/GenericConfigurationManagerImpl.cpp>
+#include <support/ErrorStr.h>
+#include <support/logging/CHIPLogging.h>
#include "fsl_reset.h"
diff --git a/src/platform/K32W/ConnectivityManagerImpl.cpp b/src/platform/K32W/ConnectivityManagerImpl.cpp
index 025d87b..19a7940 100644
--- a/src/platform/K32W/ConnectivityManagerImpl.cpp
+++ b/src/platform/K32W/ConnectivityManagerImpl.cpp
@@ -21,7 +21,7 @@
#include <platform/ConnectivityManager.h>
#include <platform/internal/BLEManager.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <lwip/dns.h>
diff --git a/src/platform/K32W/DeviceNetworkProvisioningDelegateImpl.cpp b/src/platform/K32W/DeviceNetworkProvisioningDelegateImpl.cpp
index 060c09e..2593cc7 100644
--- a/src/platform/K32W/DeviceNetworkProvisioningDelegateImpl.cpp
+++ b/src/platform/K32W/DeviceNetworkProvisioningDelegateImpl.cpp
@@ -19,6 +19,7 @@
#if CHIP_ENABLE_OPENTHREAD
#include <platform/ThreadStackManager.h>
+#include <support/ErrorMacros.h>
#endif
namespace chip {
diff --git a/src/platform/K32W/Entropy.cpp b/src/platform/K32W/Entropy.cpp
index 7c6ec34..0bbe0ad 100644
--- a/src/platform/K32W/Entropy.cpp
+++ b/src/platform/K32W/Entropy.cpp
@@ -24,6 +24,8 @@
/* this file behaves like a config.h, comes first */
#include <platform/internal/CHIPDeviceLayerInternal.h>
+#include <support/DieMacros.h>
+#include <support/ErrorMacros.h>
#include <support/crypto/CHIPRNG.h>
#include <mbedtls/entropy_poll.h>
diff --git a/src/platform/K32W/K32WConfig.cpp b/src/platform/K32W/K32WConfig.cpp
index fb3917d..1e9217c 100644
--- a/src/platform/K32W/K32WConfig.cpp
+++ b/src/platform/K32W/K32WConfig.cpp
@@ -29,6 +29,7 @@
#include <core/CHIPEncoding.h>
#include <platform/internal/testing/ConfigUnitTest.h>
+#include <support/ErrorMacros.h>
#include "FreeRTOS.h"
diff --git a/src/platform/K32W/Logging.cpp b/src/platform/K32W/Logging.cpp
index 1e803eb..2e6ec59 100644
--- a/src/platform/K32W/Logging.cpp
+++ b/src/platform/K32W/Logging.cpp
@@ -4,7 +4,7 @@
#include <core/CHIPConfig.h>
#include <platform/CHIPDeviceConfig.h>
-#include <src/lib/support/CodeUtils.h>
+#include <support/DieMacros.h>
#include <support/logging/Constants.h>
#include <cstring>
diff --git a/src/platform/Linux/BLEManagerImpl.cpp b/src/platform/Linux/BLEManagerImpl.cpp
index f0f515d..5f3c9f4 100644
--- a/src/platform/Linux/BLEManagerImpl.cpp
+++ b/src/platform/Linux/BLEManagerImpl.cpp
@@ -26,7 +26,8 @@
#include <ble/CHIPBleServiceData.h>
#include <new>
#include <platform/internal/BLEManager.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
#include <support/SafeInt.h>
#include <cassert>
diff --git a/src/platform/Linux/CHIPLinuxStorage.cpp b/src/platform/Linux/CHIPLinuxStorage.cpp
index cacb172..c5c5528 100644
--- a/src/platform/Linux/CHIPLinuxStorage.cpp
+++ b/src/platform/Linux/CHIPLinuxStorage.cpp
@@ -34,7 +34,6 @@
#include <platform/internal/CHIPDeviceLayerInternal.h>
#include <support/Base64.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <support/ScopedBuffer.h>
#include <support/logging/CHIPLogging.h>
diff --git a/src/platform/Linux/CHIPLinuxStorageIni.cpp b/src/platform/Linux/CHIPLinuxStorageIni.cpp
index 0f9fc2a..3ba9374 100644
--- a/src/platform/Linux/CHIPLinuxStorageIni.cpp
+++ b/src/platform/Linux/CHIPLinuxStorageIni.cpp
@@ -31,7 +31,6 @@
#include <platform/internal/CHIPDeviceLayerInternal.h>
#include <support/Base64.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
namespace chip {
diff --git a/src/platform/Linux/ConfigurationManagerImpl.cpp b/src/platform/Linux/ConfigurationManagerImpl.cpp
index 57090c6..b15f41d 100644
--- a/src/platform/Linux/ConfigurationManagerImpl.cpp
+++ b/src/platform/Linux/ConfigurationManagerImpl.cpp
@@ -32,7 +32,8 @@
#include <platform/ConfigurationManager.h>
#include <platform/Linux/PosixConfig.h>
#include <platform/internal/GenericConfigurationManagerImpl.cpp>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
#include <support/logging/CHIPLogging.h>
namespace chip {
diff --git a/src/platform/Linux/ConnectivityManagerImpl.cpp b/src/platform/Linux/ConnectivityManagerImpl.cpp
index f73e0dc..db5ab42 100644
--- a/src/platform/Linux/ConnectivityManagerImpl.cpp
+++ b/src/platform/Linux/ConnectivityManagerImpl.cpp
@@ -24,7 +24,8 @@
#include <cstdlib>
#include <new>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
#include <support/logging/CHIPLogging.h>
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
diff --git a/src/platform/Linux/Entropy.cpp b/src/platform/Linux/Entropy.cpp
index f1b23e4..bad71e5 100644
--- a/src/platform/Linux/Entropy.cpp
+++ b/src/platform/Linux/Entropy.cpp
@@ -23,6 +23,7 @@
*/
#include <platform/internal/CHIPDeviceLayerInternal.h>
+#include <support/ErrorMacros.h>
#include <support/crypto/CHIPRNG.h>
using namespace ::chip;
diff --git a/src/platform/Linux/KeyValueStoreManagerImpl.cpp b/src/platform/Linux/KeyValueStoreManagerImpl.cpp
index d94bc2b..d109fbe 100644
--- a/src/platform/Linux/KeyValueStoreManagerImpl.cpp
+++ b/src/platform/Linux/KeyValueStoreManagerImpl.cpp
@@ -27,7 +27,7 @@
#include <string.h>
#include <platform/Linux/CHIPLinuxStorage.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
namespace chip {
diff --git a/src/platform/Linux/MdnsImpl.cpp b/src/platform/Linux/MdnsImpl.cpp
index bd608c7..c943ef1 100644
--- a/src/platform/Linux/MdnsImpl.cpp
+++ b/src/platform/Linux/MdnsImpl.cpp
@@ -26,7 +26,8 @@
#include <netinet/in.h>
#include "support/CHIPMem.h"
-#include "support/CodeUtils.h"
+#include "support/DieMacros.h"
+#include "support/ErrorMacros.h"
using chip::Mdns::kMdnsTypeMaxSize;
using chip::Mdns::MdnsServiceProtocol;
diff --git a/src/platform/Linux/PlatformManagerImpl.cpp b/src/platform/Linux/PlatformManagerImpl.cpp
index b45e6d0..09116f2 100644
--- a/src/platform/Linux/PlatformManagerImpl.cpp
+++ b/src/platform/Linux/PlatformManagerImpl.cpp
@@ -27,6 +27,7 @@
#include <platform/PlatformManager.h>
#include <platform/internal/GenericPlatformManagerImpl_POSIX.cpp>
#include <support/CHIPMem.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <thread>
diff --git a/src/platform/Linux/PosixConfig.cpp b/src/platform/Linux/PosixConfig.cpp
index ebe9eb1..0577b55 100644
--- a/src/platform/Linux/PosixConfig.cpp
+++ b/src/platform/Linux/PosixConfig.cpp
@@ -30,7 +30,8 @@
#include <core/CHIPEncoding.h>
#include <platform/Linux/CHIPLinuxStorage.h>
#include <platform/Linux/PosixConfig.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
namespace chip {
namespace DeviceLayer {
diff --git a/src/platform/Linux/ThreadStackManagerImpl.cpp b/src/platform/Linux/ThreadStackManagerImpl.cpp
index e956192..25acda2 100644
--- a/src/platform/Linux/ThreadStackManagerImpl.cpp
+++ b/src/platform/Linux/ThreadStackManagerImpl.cpp
@@ -24,7 +24,7 @@
#include "platform/PlatformManager.h"
#include "platform/ThreadStackManager.h"
-#include "support/CodeUtils.h"
+#include "support/ErrorMacros.h"
#include "support/logging/CHIPLogging.h"
#include "dbus/client/thread_api_dbus.hpp"
diff --git a/src/platform/Linux/bluez/AdapterIterator.cpp b/src/platform/Linux/bluez/AdapterIterator.cpp
index 626b2f9..5f70f63 100644
--- a/src/platform/Linux/bluez/AdapterIterator.cpp
+++ b/src/platform/Linux/bluez/AdapterIterator.cpp
@@ -19,7 +19,7 @@
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
namespace chip {
diff --git a/src/platform/Linux/bluez/ChipDeviceScanner.cpp b/src/platform/Linux/bluez/ChipDeviceScanner.cpp
index d960e1b..0f2bf9a 100644
--- a/src/platform/Linux/bluez/ChipDeviceScanner.cpp
+++ b/src/platform/Linux/bluez/ChipDeviceScanner.cpp
@@ -25,6 +25,7 @@
#include <errno.h>
#include <pthread.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
namespace chip {
diff --git a/src/platform/Linux/bluez/Helper.cpp b/src/platform/Linux/bluez/Helper.cpp
index e2a2078..75b9647 100644
--- a/src/platform/Linux/bluez/Helper.cpp
+++ b/src/platform/Linux/bluez/Helper.cpp
@@ -56,6 +56,7 @@
#include <support/BitFlags.h>
#include <support/CHIPMem.h>
#include <support/CHIPMemString.h>
+#include <support/ErrorMacros.h>
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
#include <cassert>
@@ -68,7 +69,8 @@
#include <utility>
#include <platform/Linux/BLEManagerImpl.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ReturnMacros.h>
#include <system/TLVPacketBufferBackingStore.h>
#include "BluezObjectIterator.h"
diff --git a/src/platform/Linux/bluez/MainLoop.cpp b/src/platform/Linux/bluez/MainLoop.cpp
index 5ddc7b5..7794834 100644
--- a/src/platform/Linux/bluez/MainLoop.cpp
+++ b/src/platform/Linux/bluez/MainLoop.cpp
@@ -20,7 +20,8 @@
#include <errno.h>
#include <pthread.h>
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
namespace chip {
diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp
index 8886ebe..a542f86 100644
--- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp
+++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp
@@ -49,7 +49,9 @@
#include <platform/ThreadStackManager.h>
#include <platform/internal/CHIPDeviceLayerInternal.h>
#include <platform/internal/DeviceNetworkInfo.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
extern "C" void otSysProcessDrivers(otInstance * aInstance);
diff --git a/src/platform/Zephyr/BLEManagerImpl.cpp b/src/platform/Zephyr/BLEManagerImpl.cpp
index e3d53d9..d91a9d9 100644
--- a/src/platform/Zephyr/BLEManagerImpl.cpp
+++ b/src/platform/Zephyr/BLEManagerImpl.cpp
@@ -29,7 +29,7 @@
#include <ble/CHIPBleServiceData.h>
#include <platform/internal/BLEManager.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <logging/log.h>
diff --git a/src/platform/Zephyr/ConfigurationManagerImpl.cpp b/src/platform/Zephyr/ConfigurationManagerImpl.cpp
index c0a0a85..f27b717 100644
--- a/src/platform/Zephyr/ConfigurationManagerImpl.cpp
+++ b/src/platform/Zephyr/ConfigurationManagerImpl.cpp
@@ -33,7 +33,7 @@
#include <platform/internal/FactoryProvisioning.cpp>
#endif // CHIP_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <power/reboot.h>
diff --git a/src/platform/Zephyr/KeyValueStoreManagerImpl.cpp b/src/platform/Zephyr/KeyValueStoreManagerImpl.cpp
index dfbc671..3d80ab0 100644
--- a/src/platform/Zephyr/KeyValueStoreManagerImpl.cpp
+++ b/src/platform/Zephyr/KeyValueStoreManagerImpl.cpp
@@ -22,7 +22,8 @@
*/
#include <platform/KeyValueStoreManager.h>
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
#include <logging/log.h>
diff --git a/src/platform/Zephyr/PlatformManagerImpl.cpp b/src/platform/Zephyr/PlatformManagerImpl.cpp
index 4cf9244..5440b99 100644
--- a/src/platform/Zephyr/PlatformManagerImpl.cpp
+++ b/src/platform/Zephyr/PlatformManagerImpl.cpp
@@ -26,6 +26,7 @@
#include <platform/PlatformManager.h>
#include <platform/internal/GenericPlatformManagerImpl_Zephyr.cpp>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
namespace chip {
diff --git a/src/platform/Zephyr/ZephyrConfig.cpp b/src/platform/Zephyr/ZephyrConfig.cpp
index 6ac82ba..326a6ca 100644
--- a/src/platform/Zephyr/ZephyrConfig.cpp
+++ b/src/platform/Zephyr/ZephyrConfig.cpp
@@ -27,7 +27,7 @@
#include <core/CHIPEncoding.h>
#include <platform/internal/testing/ConfigUnitTest.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <settings/settings.h>
diff --git a/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp b/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp
index f228677..eae7d8d 100644
--- a/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp
+++ b/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp
@@ -29,7 +29,7 @@
#include <core/CHIPEncoding.h>
#include <platform/cc13x2_26x2/CC13X2_26X2Config.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <ti/common/nv/nvintf.h>
#include <ti/common/nv/nvocmp.h>
diff --git a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp
index c630c1f..ffeaa19 100644
--- a/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp
+++ b/src/platform/cc13x2_26x2/ConfigurationManagerImpl.cpp
@@ -32,7 +32,6 @@
#include <core/CHIPVendorIdentifiers.hpp>
#include <platform/cc13x2_26x2/CC13X2_26X2Config.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#pragma GCC diagnostic push
diff --git a/src/platform/cc13x2_26x2/ConnectivityManagerImpl.cpp b/src/platform/cc13x2_26x2/ConnectivityManagerImpl.cpp
index 5308d9e..d58c4fa 100644
--- a/src/platform/cc13x2_26x2/ConnectivityManagerImpl.cpp
+++ b/src/platform/cc13x2_26x2/ConnectivityManagerImpl.cpp
@@ -34,7 +34,6 @@
#include <platform/ConnectivityManager.h>
#include <platform/internal/BLEManager.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#include <lwip/dns.h>
diff --git a/src/platform/nrfconnect/ConnectivityManagerImpl.cpp b/src/platform/nrfconnect/ConnectivityManagerImpl.cpp
index b79bffb..7a3cbb5 100644
--- a/src/platform/nrfconnect/ConnectivityManagerImpl.cpp
+++ b/src/platform/nrfconnect/ConnectivityManagerImpl.cpp
@@ -20,7 +20,6 @@
#include <platform/ConnectivityManager.h>
#include <platform/internal/BLEManager.h>
-#include <support/CodeUtils.h>
#include <support/logging/CHIPLogging.h>
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
diff --git a/src/platform/qpg6100/BLEManagerImpl.cpp b/src/platform/qpg6100/BLEManagerImpl.cpp
index 3764b7b..8672e80 100644
--- a/src/platform/qpg6100/BLEManagerImpl.cpp
+++ b/src/platform/qpg6100/BLEManagerImpl.cpp
@@ -29,7 +29,8 @@
#include <ble/CHIPBleServiceData.h>
#include <platform/internal/BLEManager.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
#include <support/logging/CHIPLogging.h>
using namespace ::chip;
diff --git a/src/platform/qpg6100/ConfigurationManagerImpl.cpp b/src/platform/qpg6100/ConfigurationManagerImpl.cpp
index eea5826..1611f66 100644
--- a/src/platform/qpg6100/ConfigurationManagerImpl.cpp
+++ b/src/platform/qpg6100/ConfigurationManagerImpl.cpp
@@ -28,12 +28,14 @@
#include <core/CHIPVendorIdentifiers.hpp>
#include <platform/qpg6100/qpg6100Config.h>
+#include <support/ErrorStr.h>
#if CHIP_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING
#include <platform/internal/FactoryProvisioning.cpp>
#endif // CHIP_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
#include <support/logging/CHIPLogging.h>
namespace chip {
diff --git a/src/platform/qpg6100/ConnectivityManagerImpl.cpp b/src/platform/qpg6100/ConnectivityManagerImpl.cpp
index f1e6edf..5da0f05 100644
--- a/src/platform/qpg6100/ConnectivityManagerImpl.cpp
+++ b/src/platform/qpg6100/ConnectivityManagerImpl.cpp
@@ -27,7 +27,7 @@
#include <platform/ConnectivityManager.h>
#include <platform/internal/BLEManager.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <lwip/dns.h>
diff --git a/src/platform/qpg6100/DeviceNetworkProvisioningDelegateImpl.cpp b/src/platform/qpg6100/DeviceNetworkProvisioningDelegateImpl.cpp
index 4a75640..648930c 100644
--- a/src/platform/qpg6100/DeviceNetworkProvisioningDelegateImpl.cpp
+++ b/src/platform/qpg6100/DeviceNetworkProvisioningDelegateImpl.cpp
@@ -19,6 +19,7 @@
#if CHIP_ENABLE_OPENTHREAD
#include <platform/ThreadStackManager.h>
+#include <support/ErrorMacros.h>
#endif
namespace chip {
diff --git a/src/platform/qpg6100/Entropy.cpp b/src/platform/qpg6100/Entropy.cpp
index 9c6f87b..74efee6 100644
--- a/src/platform/qpg6100/Entropy.cpp
+++ b/src/platform/qpg6100/Entropy.cpp
@@ -43,6 +43,8 @@
//
#include <platform/internal/CHIPDeviceLayerInternal.h>
+#include <support/DieMacros.h>
+#include <support/ErrorMacros.h>
#include <support/crypto/CHIPRNG.h>
#include <openthread/platform/random.h>
diff --git a/src/platform/qpg6100/ThreadStackManagerImpl.cpp b/src/platform/qpg6100/ThreadStackManagerImpl.cpp
index a68d56a..ff01559 100644
--- a/src/platform/qpg6100/ThreadStackManagerImpl.cpp
+++ b/src/platform/qpg6100/ThreadStackManagerImpl.cpp
@@ -33,6 +33,7 @@
#include <support/CHIPMem.h>
#include <support/CHIPPlatformMemory.h>
+#include <support/ErrorMacros.h>
#include <openthread/heap.h>
// Qorvo OpenThread functions
diff --git a/src/platform/qpg6100/qpg6100Config.cpp b/src/platform/qpg6100/qpg6100Config.cpp
index 6fc4f08..d967fbc 100644
--- a/src/platform/qpg6100/qpg6100Config.cpp
+++ b/src/platform/qpg6100/qpg6100Config.cpp
@@ -27,7 +27,7 @@
#include <core/CHIPEncoding.h>
#include <platform/internal/testing/ConfigUnitTest.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include "FreeRTOS.h"
diff --git a/src/platform/tests/TestCHIPoBLEStackMgr.cpp b/src/platform/tests/TestCHIPoBLEStackMgr.cpp
index 08a5976..1ac2b2f 100644
--- a/src/platform/tests/TestCHIPoBLEStackMgr.cpp
+++ b/src/platform/tests/TestCHIPoBLEStackMgr.cpp
@@ -19,7 +19,6 @@
#include <assert.h>
#include <memory>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <support/UnitTestRegistration.h>
#include "platform/PlatformManager.h"
diff --git a/src/platform/tests/TestConfigurationMgr.cpp b/src/platform/tests/TestConfigurationMgr.cpp
index 2a5734f..1151e44 100644
--- a/src/platform/tests/TestConfigurationMgr.cpp
+++ b/src/platform/tests/TestConfigurationMgr.cpp
@@ -30,7 +30,6 @@
#include <nlunit-test.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <support/UnitTestRegistration.h>
#include <platform/CHIPDeviceLayer.h>
diff --git a/src/platform/tests/TestPlatformMgr.cpp b/src/platform/tests/TestPlatformMgr.cpp
index 981fe63..20f0b5b 100644
--- a/src/platform/tests/TestPlatformMgr.cpp
+++ b/src/platform/tests/TestPlatformMgr.cpp
@@ -30,7 +30,6 @@
#include <nlunit-test.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <support/UnitTestRegistration.h>
#include <platform/CHIPDeviceLayer.h>
diff --git a/src/protocols/bdx/BdxMessages.cpp b/src/protocols/bdx/BdxMessages.cpp
index bd9bf78..c2bcaeb 100644
--- a/src/protocols/bdx/BdxMessages.cpp
+++ b/src/protocols/bdx/BdxMessages.cpp
@@ -25,7 +25,7 @@
#include <support/BufferReader.h>
#include <support/BufferWriter.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <limits>
#include <utility>
diff --git a/src/protocols/bdx/BdxMessages.h b/src/protocols/bdx/BdxMessages.h
index e65fd8c..95f0c80 100644
--- a/src/protocols/bdx/BdxMessages.h
+++ b/src/protocols/bdx/BdxMessages.h
@@ -24,11 +24,13 @@
#pragma once
+#include <core/CHIPError.h>
#include <protocols/Protocols.h>
#include <support/BitFlags.h>
#include <support/BufferWriter.h>
#include <support/CodeUtils.h>
#include <system/SystemPacketBuffer.h>
+
namespace chip {
namespace bdx {
diff --git a/src/protocols/bdx/BdxTransferSession.cpp b/src/protocols/bdx/BdxTransferSession.cpp
index 0cb1888..53ee313 100644
--- a/src/protocols/bdx/BdxTransferSession.cpp
+++ b/src/protocols/bdx/BdxTransferSession.cpp
@@ -12,6 +12,8 @@
#include <protocols/secure_channel/StatusReport.h>
#include <support/BufferReader.h>
#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ReturnMacros.h>
#include <system/SystemPacketBuffer.h>
#include <transport/SecureSessionMgr.h>
diff --git a/src/protocols/bdx/tests/TestBdxMessages.cpp b/src/protocols/bdx/tests/TestBdxMessages.cpp
index 3fd9b4d..e6b5cfa 100644
--- a/src/protocols/bdx/tests/TestBdxMessages.cpp
+++ b/src/protocols/bdx/tests/TestBdxMessages.cpp
@@ -4,7 +4,6 @@
#include <support/BufferWriter.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <support/UnitTestRegistration.h>
#include <limits>
diff --git a/src/protocols/bdx/tests/TestBdxTransferSession.cpp b/src/protocols/bdx/tests/TestBdxTransferSession.cpp
index 1dbf834..6609ae3 100644
--- a/src/protocols/bdx/tests/TestBdxTransferSession.cpp
+++ b/src/protocols/bdx/tests/TestBdxTransferSession.cpp
@@ -11,7 +11,8 @@
#include <protocols/secure_channel/StatusReport.h>
#include <support/BufferReader.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ReturnMacros.h>
#include <support/UnitTestRegistration.h>
#include <system/SystemPacketBuffer.h>
diff --git a/src/protocols/echo/Echo.h b/src/protocols/echo/Echo.h
index 02f3535..cf0f8bc 100644
--- a/src/protocols/echo/Echo.h
+++ b/src/protocols/echo/Echo.h
@@ -30,7 +30,6 @@
#include <messaging/ExchangeMgr.h>
#include <messaging/Flags.h>
#include <protocols/Protocols.h>
-#include <support/CodeUtils.h>
#include <support/DLLUtil.h>
#include <support/logging/CHIPLogging.h>
diff --git a/src/protocols/echo/EchoClient.cpp b/src/protocols/echo/EchoClient.cpp
index 6feeafe..7689665 100644
--- a/src/protocols/echo/EchoClient.cpp
+++ b/src/protocols/echo/EchoClient.cpp
@@ -25,6 +25,8 @@
#include "Echo.h"
+#include <support/DieMacros.h>
+
namespace chip {
namespace Protocols {
namespace Echo {
diff --git a/src/protocols/secure_channel/Constants.h b/src/protocols/secure_channel/Constants.h
index 303244c..db27381 100644
--- a/src/protocols/secure_channel/Constants.h
+++ b/src/protocols/secure_channel/Constants.h
@@ -26,7 +26,6 @@
#pragma once
#include <protocols/Protocols.h>
-#include <support/CodeUtils.h>
/**
* @namespace chip::Protocols::SecureChannel
diff --git a/src/setup_payload/AdditionalDataPayloadGenerator.cpp b/src/setup_payload/AdditionalDataPayloadGenerator.cpp
index 341c0e6..42f547f 100644
--- a/src/setup_payload/AdditionalDataPayloadGenerator.cpp
+++ b/src/setup_payload/AdditionalDataPayloadGenerator.cpp
@@ -33,6 +33,8 @@
#include <stdlib.h>
#include <support/BufferWriter.h>
#include <support/CHIPMem.h>
+#include <support/ErrorMacros.h>
+#include <support/logging/CHIPLogging.h>
using namespace chip;
using namespace chip::System;
diff --git a/src/setup_payload/AdditionalDataPayloadParser.cpp b/src/setup_payload/AdditionalDataPayloadParser.cpp
index 053cd4d..15c5f1e 100644
--- a/src/setup_payload/AdditionalDataPayloadParser.cpp
+++ b/src/setup_payload/AdditionalDataPayloadParser.cpp
@@ -31,7 +31,7 @@
#include <core/CHIPTLVData.hpp>
#include <core/CHIPTLVUtilities.hpp>
#include <protocols/Protocols.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
namespace chip {
diff --git a/src/setup_payload/QRCodeSetupPayloadGenerator.cpp b/src/setup_payload/QRCodeSetupPayloadGenerator.cpp
index 6a277d2..f25d942 100644
--- a/src/setup_payload/QRCodeSetupPayloadGenerator.cpp
+++ b/src/setup_payload/QRCodeSetupPayloadGenerator.cpp
@@ -32,6 +32,7 @@
#include <core/CHIPTLVUtilities.hpp>
#include <protocols/Protocols.h>
#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/RandUtils.h>
#include <stdlib.h>
diff --git a/src/setup_payload/QRCodeSetupPayloadParser.cpp b/src/setup_payload/QRCodeSetupPayloadParser.cpp
index a0a1cb7..201f8a4 100644
--- a/src/setup_payload/QRCodeSetupPayloadParser.cpp
+++ b/src/setup_payload/QRCodeSetupPayloadParser.cpp
@@ -34,10 +34,12 @@
#include <core/CHIPTLVData.hpp>
#include <core/CHIPTLVUtilities.hpp>
#include <protocols/Protocols.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/RandUtils.h>
+#include <support/ReturnMacros.h>
#include <support/SafeInt.h>
#include <support/ScopedBuffer.h>
+#include <support/logging/CHIPLogging.h>
namespace chip {
diff --git a/src/setup_payload/SetupPayload.cpp b/src/setup_payload/SetupPayload.cpp
index 2888a39..ac0b7db 100644
--- a/src/setup_payload/SetupPayload.cpp
+++ b/src/setup_payload/SetupPayload.cpp
@@ -27,7 +27,7 @@
#include <core/CHIPTLV.h>
#include <core/CHIPTLVData.hpp>
#include <core/CHIPTLVUtilities.hpp>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/RandUtils.h>
#include <utility>
diff --git a/src/setup_payload/SetupPayloadHelper.cpp b/src/setup_payload/SetupPayloadHelper.cpp
index 234d28d..90173b2 100644
--- a/src/setup_payload/SetupPayloadHelper.cpp
+++ b/src/setup_payload/SetupPayloadHelper.cpp
@@ -22,7 +22,7 @@
#include <fstream>
#include <utility>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
using namespace chip;
diff --git a/src/system/SystemClock.cpp b/src/system/SystemClock.cpp
index a4b45b2..0d9675e 100644
--- a/src/system/SystemClock.cpp
+++ b/src/system/SystemClock.cpp
@@ -42,7 +42,7 @@
// common private
#include "SystemLayerPrivate.h"
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
#include <system/SystemError.h>
#if CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS
diff --git a/src/system/SystemLayer.cpp b/src/system/SystemLayer.cpp
index aa0ebb5..8a03cc4 100644
--- a/src/system/SystemLayer.cpp
+++ b/src/system/SystemLayer.cpp
@@ -34,8 +34,10 @@
// Include additional CHIP headers
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <support/DLLUtil.h>
+#include <support/DieMacros.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
#include <support/logging/CHIPLogging.h>
// Include system and language headers
diff --git a/src/system/SystemObject.cpp b/src/system/SystemObject.cpp
index c909f94..f04e07a 100644
--- a/src/system/SystemObject.cpp
+++ b/src/system/SystemObject.cpp
@@ -29,7 +29,7 @@
#include "SystemLayerPrivate.h"
// Include local headers
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
#include <system/SystemLayer.h>
// Include local headers
diff --git a/src/system/SystemPacketBuffer.cpp b/src/system/SystemPacketBuffer.cpp
index 0727a5c..9a2b8d3 100644
--- a/src/system/SystemPacketBuffer.cpp
+++ b/src/system/SystemPacketBuffer.cpp
@@ -35,7 +35,7 @@
#include "SystemLayerPrivate.h"
// Include local headers
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
#include <support/SafeInt.h>
#include <support/logging/CHIPLogging.h>
#include <system/SystemFaultInjection.h>
@@ -57,6 +57,7 @@
#if CHIP_SYSTEM_PACKETBUFFER_STORE == CHIP_SYSTEM_PACKETBUFFER_STORE_CHIP_HEAP
#include <support/CHIPMem.h>
+#include <support/DieMacros.h>
#endif
namespace chip {
diff --git a/src/system/SystemPacketBuffer.h b/src/system/SystemPacketBuffer.h
index 13854a0..a5a1339 100644
--- a/src/system/SystemPacketBuffer.h
+++ b/src/system/SystemPacketBuffer.h
@@ -29,6 +29,7 @@
#include <system/SystemConfig.h>
// Include dependent headers
+#include <core/CHIPError.h>
#include <support/BufferWriter.h>
#include <support/CodeUtils.h>
#include <support/DLLUtil.h>
diff --git a/src/system/SystemTimer.cpp b/src/system/SystemTimer.cpp
index 48da9ff..f38afdb 100644
--- a/src/system/SystemTimer.cpp
+++ b/src/system/SystemTimer.cpp
@@ -36,7 +36,8 @@
#include <system/SystemFaultInjection.h>
#include <system/SystemLayer.h>
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
+#include <support/ErrorMacros.h>
/*******************************************************************************
* Timer state
diff --git a/src/system/SystemWakeEvent.cpp b/src/system/SystemWakeEvent.cpp
index 153adee..8e91774 100644
--- a/src/system/SystemWakeEvent.cpp
+++ b/src/system/SystemWakeEvent.cpp
@@ -26,7 +26,6 @@
#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
// Include additional CHIP headers
-#include <support/CodeUtils.h>
// Include system and language headers
#include <errno.h>
diff --git a/src/system/tests/TestSystemErrorStr.cpp b/src/system/tests/TestSystemErrorStr.cpp
index 878b4f4..93e84af 100644
--- a/src/system/tests/TestSystemErrorStr.cpp
+++ b/src/system/tests/TestSystemErrorStr.cpp
@@ -37,7 +37,6 @@
#include <string.h>
#include <inet/InetError.h>
-#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
#include <support/UnitTestRegistration.h>
diff --git a/src/system/tests/TestSystemObject.cpp b/src/system/tests/TestSystemObject.cpp
index 29079f2..9d18249 100644
--- a/src/system/tests/TestSystemObject.cpp
+++ b/src/system/tests/TestSystemObject.cpp
@@ -37,7 +37,6 @@
#include <system/SystemLayer.h>
-#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
#include <support/UnitTestRegistration.h>
diff --git a/src/system/tests/TestSystemPacketBuffer.cpp b/src/system/tests/TestSystemPacketBuffer.cpp
index e2c199c..cfeec07 100644
--- a/src/system/tests/TestSystemPacketBuffer.cpp
+++ b/src/system/tests/TestSystemPacketBuffer.cpp
@@ -35,7 +35,6 @@
#include <vector>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <support/UnitTestRegistration.h>
#include <system/SystemPacketBuffer.h>
diff --git a/src/system/tests/TestSystemTimer.cpp b/src/system/tests/TestSystemTimer.cpp
index d8eb573..d2c4e71 100644
--- a/src/system/tests/TestSystemTimer.cpp
+++ b/src/system/tests/TestSystemTimer.cpp
@@ -30,7 +30,6 @@
#include <system/SystemConfig.h>
#include <nlunit-test.h>
-#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
#include <support/UnitTestRegistration.h>
#include <system/SystemError.h>
diff --git a/src/system/tests/TestSystemWakeEvent.cpp b/src/system/tests/TestSystemWakeEvent.cpp
index 375fefe..8453ab9 100644
--- a/src/system/tests/TestSystemWakeEvent.cpp
+++ b/src/system/tests/TestSystemWakeEvent.cpp
@@ -28,7 +28,6 @@
#include <system/SystemConfig.h>
#include <nlunit-test.h>
-#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
#include <support/UnitTestRegistration.h>
#include <system/SystemError.h>
diff --git a/src/system/tests/TestTimeSource.cpp b/src/system/tests/TestTimeSource.cpp
index 1422b04..4c58db7 100644
--- a/src/system/tests/TestTimeSource.cpp
+++ b/src/system/tests/TestTimeSource.cpp
@@ -28,7 +28,6 @@
#include <system/SystemConfig.h>
#include <nlunit-test.h>
-#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
#include <support/UnitTestRegistration.h>
#include <system/TimeSource.h>
diff --git a/src/test_driver/nrfconnect/main/runner.cpp b/src/test_driver/nrfconnect/main/runner.cpp
index f536996..693ea01 100644
--- a/src/test_driver/nrfconnect/main/runner.cpp
+++ b/src/test_driver/nrfconnect/main/runner.cpp
@@ -16,7 +16,7 @@
*/
#include <platform/CHIPDeviceLayer.h>
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
#include <support/ErrorStr.h>
#include <support/UnitTestRegistration.h>
diff --git a/src/transport/AdminPairingTable.cpp b/src/transport/AdminPairingTable.cpp
index 6a61834..7a8bd5f 100644
--- a/src/transport/AdminPairingTable.cpp
+++ b/src/transport/AdminPairingTable.cpp
@@ -19,8 +19,11 @@
* @brief Defines a table of admins that have provisioned the device.
*/
+#include <cstdio>
+
#include <core/CHIPEncoding.h>
#include <support/CHIPMem.h>
+#include <support/ReturnMacros.h>
#include <support/SafeInt.h>
#include <transport/AdminPairingTable.h>
diff --git a/src/transport/BLE.cpp b/src/transport/BLE.cpp
index 47ca32c..87aae55 100644
--- a/src/transport/BLE.cpp
+++ b/src/transport/BLE.cpp
@@ -24,7 +24,9 @@
#include <transport/BLE.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
#include <transport/raw/MessageHeader.h>
diff --git a/src/transport/CASESession.cpp b/src/transport/CASESession.cpp
index 3c6d0ff..3789948 100644
--- a/src/transport/CASESession.cpp
+++ b/src/transport/CASESession.cpp
@@ -32,7 +32,8 @@
#include <core/CHIPSafeCasts.h>
#include <protocols/Protocols.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ReturnMacros.h>
#include <support/SafeInt.h>
#include <transport/SecureSessionMgr.h>
diff --git a/src/transport/NetworkProvisioning.cpp b/src/transport/NetworkProvisioning.cpp
index e1dfabf..2883724 100644
--- a/src/transport/NetworkProvisioning.cpp
+++ b/src/transport/NetworkProvisioning.cpp
@@ -19,7 +19,7 @@
#include <core/CHIPSafeCasts.h>
#include <platform/internal/DeviceNetworkInfo.h>
#include <protocols/Protocols.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/ErrorStr.h>
#include <support/SafeInt.h>
#include <transport/NetworkProvisioning.h>
diff --git a/src/transport/PASESession.cpp b/src/transport/PASESession.cpp
index 7f61424..e86934b 100644
--- a/src/transport/PASESession.cpp
+++ b/src/transport/PASESession.cpp
@@ -39,7 +39,8 @@
#include <setup_payload/SetupPayload.h>
#include <support/BufferWriter.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ReturnMacros.h>
#include <support/SafeInt.h>
#include <transport/SecureSessionMgr.h>
diff --git a/src/transport/RendezvousSession.cpp b/src/transport/RendezvousSession.cpp
index 3ec0214..a4bf5c6 100644
--- a/src/transport/RendezvousSession.cpp
+++ b/src/transport/RendezvousSession.cpp
@@ -20,8 +20,8 @@
#include <core/CHIPSafeCasts.h>
#include <platform/internal/DeviceNetworkInfo.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
#include <support/SafeInt.h>
#include <transport/RendezvousSession.h>
#include <transport/SecureMessageCodec.h>
diff --git a/src/transport/SecureMessageCodec.cpp b/src/transport/SecureMessageCodec.cpp
index 1f7e424..fa7a82d 100644
--- a/src/transport/SecureMessageCodec.cpp
+++ b/src/transport/SecureMessageCodec.cpp
@@ -25,8 +25,9 @@
*
*/
-#include <support/CodeUtils.h>
+#include <support/ReturnMacros.h>
#include <support/SafeInt.h>
+#include <support/logging/CHIPLogging.h>
#include <transport/SecureMessageCodec.h>
// Maximum length of application data that can be encrypted as one block.
diff --git a/src/transport/SecureSession.cpp b/src/transport/SecureSession.cpp
index 5d47267..7128d9b 100644
--- a/src/transport/SecureSession.cpp
+++ b/src/transport/SecureSession.cpp
@@ -24,7 +24,7 @@
#include <core/CHIPEncoding.h>
#include <support/BufferWriter.h>
-#include <support/CodeUtils.h>
+#include <support/ReturnMacros.h>
#include <transport/SecureSession.h>
#include <transport/raw/MessageHeader.h>
diff --git a/src/transport/SecureSessionMgr.cpp b/src/transport/SecureSessionMgr.cpp
index 872a738..dfde326 100644
--- a/src/transport/SecureSessionMgr.cpp
+++ b/src/transport/SecureSessionMgr.cpp
@@ -31,7 +31,10 @@
#include <core/CHIPKeyIds.h>
#include <platform/CHIPDeviceLayer.h>
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
#include <support/SafeInt.h>
#include <support/logging/CHIPLogging.h>
#include <transport/AdminPairingTable.h>
diff --git a/src/transport/SecureSessionMgr.h b/src/transport/SecureSessionMgr.h
index dde09aa..7cd6fbb 100644
--- a/src/transport/SecureSessionMgr.h
+++ b/src/transport/SecureSessionMgr.h
@@ -30,7 +30,6 @@
#include <core/CHIPCore.h>
#include <inet/IPAddress.h>
#include <inet/IPEndPointBasis.h>
-#include <support/CodeUtils.h>
#include <support/DLLUtil.h>
#include <transport/AdminPairingTable.h>
#include <transport/PASESession.h>
diff --git a/src/transport/StorablePeerConnection.cpp b/src/transport/StorablePeerConnection.cpp
index 647b18e..5d5feb8 100644
--- a/src/transport/StorablePeerConnection.cpp
+++ b/src/transport/StorablePeerConnection.cpp
@@ -16,6 +16,7 @@
*/
#include <core/CHIPEncoding.h>
+#include <support/ReturnMacros.h>
#include <support/SafeInt.h>
#include <transport/StorablePeerConnection.h>
diff --git a/src/transport/TransportMgr.h b/src/transport/TransportMgr.h
index 0084338..b48d4a6 100644
--- a/src/transport/TransportMgr.h
+++ b/src/transport/TransportMgr.h
@@ -27,7 +27,7 @@
#pragma once
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
#include <support/logging/CHIPLogging.h>
#include <transport/TransportMgrBase.h>
#include <transport/raw/Base.h>
diff --git a/src/transport/TransportMgrBase.cpp b/src/transport/TransportMgrBase.cpp
index 39c6749..814e1a1 100644
--- a/src/transport/TransportMgrBase.cpp
+++ b/src/transport/TransportMgrBase.cpp
@@ -16,7 +16,6 @@
#include <transport/TransportMgrBase.h>
-#include <support/CodeUtils.h>
#include <transport/TransportMgr.h>
#include <transport/raw/Base.h>
diff --git a/src/transport/TransportMgrBase.h b/src/transport/TransportMgrBase.h
index 9e1c722..507c5c1 100644
--- a/src/transport/TransportMgrBase.h
+++ b/src/transport/TransportMgrBase.h
@@ -16,7 +16,6 @@
#pragma once
-#include <support/CodeUtils.h>
#include <system/SystemPacketBuffer.h>
#include <transport/raw/Base.h>
#include <transport/raw/MessageHeader.h>
diff --git a/src/transport/raw/MessageHeader.cpp b/src/transport/raw/MessageHeader.cpp
index 564e953..03655be 100644
--- a/src/transport/raw/MessageHeader.cpp
+++ b/src/transport/raw/MessageHeader.cpp
@@ -31,7 +31,8 @@
#include <core/CHIPError.h>
#include <support/BufferReader.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ReturnMacros.h>
/**********************************************
* Header format (little endian):
diff --git a/src/transport/raw/TCP.cpp b/src/transport/raw/TCP.cpp
index b8d8746..1ddf3b3 100644
--- a/src/transport/raw/TCP.cpp
+++ b/src/transport/raw/TCP.cpp
@@ -26,7 +26,9 @@
#include <transport/raw/TCP.h>
#include <core/CHIPEncoding.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
#include <transport/raw/MessageHeader.h>
diff --git a/src/transport/raw/TCP.h b/src/transport/raw/TCP.h
index 6ea5ebc..3278ad5 100644
--- a/src/transport/raw/TCP.h
+++ b/src/transport/raw/TCP.h
@@ -33,7 +33,7 @@
#include <inet/IPEndPointBasis.h>
#include <inet/InetInterface.h>
#include <inet/TCPEndPoint.h>
-#include <support/CodeUtils.h>
+#include <support/ReturnMacros.h>
#include <transport/raw/Base.h>
namespace chip {
diff --git a/src/transport/raw/UDP.cpp b/src/transport/raw/UDP.cpp
index aa78468..e44497f 100644
--- a/src/transport/raw/UDP.cpp
+++ b/src/transport/raw/UDP.cpp
@@ -23,7 +23,9 @@
*/
#include <transport/raw/UDP.h>
-#include <support/CodeUtils.h>
+#include <support/ErrorMacros.h>
+#include <support/ErrorStr.h>
+#include <support/ReturnMacros.h>
#include <support/logging/CHIPLogging.h>
#include <transport/raw/MessageHeader.h>
diff --git a/src/transport/raw/tests/NetworkTestHelpers.cpp b/src/transport/raw/tests/NetworkTestHelpers.cpp
index 281fab2..484aefd 100644
--- a/src/transport/raw/tests/NetworkTestHelpers.cpp
+++ b/src/transport/raw/tests/NetworkTestHelpers.cpp
@@ -20,7 +20,6 @@
#include <inet/tests/TestInetCommon.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
namespace chip {
diff --git a/src/transport/raw/tests/TestMessageHeader.cpp b/src/transport/raw/tests/TestMessageHeader.cpp
index edf0e3b..1c9278e 100644
--- a/src/transport/raw/tests/TestMessageHeader.cpp
+++ b/src/transport/raw/tests/TestMessageHeader.cpp
@@ -23,7 +23,6 @@
*
*/
#include <protocols/Protocols.h>
-#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
#include <support/UnitTestRegistration.h>
#include <transport/raw/MessageHeader.h>
diff --git a/src/transport/raw/tests/TestTCP.cpp b/src/transport/raw/tests/TestTCP.cpp
index e8f91c6..16c39b7 100644
--- a/src/transport/raw/tests/TestTCP.cpp
+++ b/src/transport/raw/tests/TestTCP.cpp
@@ -26,7 +26,6 @@
#include <core/CHIPCore.h>
#include <core/CHIPEncoding.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <support/UnitTestRegistration.h>
#include <system/SystemLayer.h>
#include <system/SystemObject.h>
diff --git a/src/transport/raw/tests/TestUDP.cpp b/src/transport/raw/tests/TestUDP.cpp
index f2400a1..301cd38 100644
--- a/src/transport/raw/tests/TestUDP.cpp
+++ b/src/transport/raw/tests/TestUDP.cpp
@@ -24,7 +24,6 @@
#include "NetworkTestHelpers.h"
#include <core/CHIPCore.h>
-#include <support/CodeUtils.h>
#include <support/UnitTestRegistration.h>
#include <transport/TransportMgr.h>
#include <transport/raw/UDP.h>
diff --git a/src/transport/tests/TestPASESession.cpp b/src/transport/tests/TestPASESession.cpp
index 2c31512..c86b331 100644
--- a/src/transport/tests/TestPASESession.cpp
+++ b/src/transport/tests/TestPASESession.cpp
@@ -28,7 +28,6 @@
#include <core/CHIPSafeCasts.h>
#include <stdarg.h>
#include <support/CHIPMem.h>
-#include <support/CodeUtils.h>
#include <support/UnitTestRegistration.h>
#include <transport/PASESession.h>
diff --git a/src/transport/tests/TestPeerConnections.cpp b/src/transport/tests/TestPeerConnections.cpp
index 49c720b..67893d3 100644
--- a/src/transport/tests/TestPeerConnections.cpp
+++ b/src/transport/tests/TestPeerConnections.cpp
@@ -22,7 +22,7 @@
* the PeerConnections class within the transport layer
*
*/
-#include <support/CodeUtils.h>
+#include <support/DieMacros.h>
#include <support/ErrorStr.h>
#include <support/UnitTestRegistration.h>
#include <transport/PeerConnections.h>
diff --git a/src/transport/tests/TestSecureSession.cpp b/src/transport/tests/TestSecureSession.cpp
index b9e6c7a..8c14c7d 100644
--- a/src/transport/tests/TestSecureSession.cpp
+++ b/src/transport/tests/TestSecureSession.cpp
@@ -28,7 +28,6 @@
#include <transport/SecureSession.h>
#include <stdarg.h>
-#include <support/CodeUtils.h>
#include <support/UnitTestRegistration.h>
using namespace chip;
diff --git a/src/transport/tests/TestSecureSessionMgr.cpp b/src/transport/tests/TestSecureSessionMgr.cpp
index 22fd11e..5ddf40e 100644
--- a/src/transport/tests/TestSecureSessionMgr.cpp
+++ b/src/transport/tests/TestSecureSessionMgr.cpp
@@ -27,7 +27,7 @@
#include <core/CHIPCore.h>
#include <protocols/Protocols.h>
#include <protocols/echo/Echo.h>
-#include <support/CodeUtils.h>
+#include <support/ReturnMacros.h>
#include <support/UnitTestRegistration.h>
#include <transport/SecureSessionMgr.h>
#include <transport/TransportMgr.h>