Skip to content

Commit

Permalink
Stop using __FILE__ in various logging in device code. (#15523)
Browse files Browse the repository at this point in the history
Stops using ReturnErrorOnFailure, LogErrorOnFailure and
ReturnLogErrorOnFailure in core code.  Converts VerifyOrReturnLogError
to not using __FILE__ when CHIP_CONFIG_ERROR_SOURCE is not defined.
  • Loading branch information
bzbarsky-apple authored Feb 25, 2022
1 parent e3d3539 commit 980e177
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
12 changes: 10 additions & 2 deletions src/app/CASESessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,22 @@ void CASESessionManager::OnOperationalNodeResolved(const Dnssd::ResolvedNodeData

if (mConfig.dnsCache != nullptr)
{
LogErrorOnFailure(mConfig.dnsCache->Insert(nodeData));
CHIP_ERROR err = mConfig.dnsCache->Insert(nodeData);
if (err != CHIP_NO_ERROR)
{
ChipLogError(Controller, "DNS Cache insert: %" CHIP_ERROR_FORMAT, err.Format());
}
}

OperationalDeviceProxy * session = FindExistingSession(nodeData.mPeerId);
VerifyOrReturn(session != nullptr,
ChipLogDetail(Controller, "OnNodeIdResolved was called for a device with no active sessions, ignoring it."));

LogErrorOnFailure(session->UpdateDeviceData(OperationalDeviceProxy::ToPeerAddress(nodeData), nodeData.GetMRPConfig()));
CHIP_ERROR err = session->UpdateDeviceData(OperationalDeviceProxy::ToPeerAddress(nodeData), nodeData.GetMRPConfig());
if (err != CHIP_NO_ERROR)
{
ChipLogError(Controller, "Update Service Data: %" CHIP_ERROR_FORMAT, err.Format());
}
}

void CASESessionManager::OnOperationalNodeResolutionFailed(const PeerId & peer, CHIP_ERROR error)
Expand Down
2 changes: 1 addition & 1 deletion src/app/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ CHIP_ERROR CommandHandler::AddStatusInternal(const ConcreteCommandPath & aComman
const Optional<ClusterStatus> & aClusterStatus)
{
StatusIB statusIB;
ReturnLogErrorOnFailure(PrepareStatus(aCommandPath));
ReturnErrorOnFailure(PrepareStatus(aCommandPath));
CommandStatusIB::Builder & commandStatus = mInvokeResponseBuilder.GetInvokeResponses().GetInvokeResponse().GetStatus();
StatusIB::Builder & statusIBBuilder = commandStatus.CreateErrorStatus();
ReturnErrorOnFailure(commandStatus.GetError());
Expand Down
6 changes: 3 additions & 3 deletions src/app/CommandSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ CHIP_ERROR CommandSender::ProcessInvokeResponseIB(InvokeResponseIB::Parser & aIn

CHIP_ERROR CommandSender::PrepareCommand(const CommandPathParams & aCommandPathParams, bool aStartDataStruct)
{
ReturnLogErrorOnFailure(AllocateBuffer());
ReturnErrorOnFailure(AllocateBuffer());

//
// We must not be in the middle of preparing a command, or having prepared or sent one.
Expand All @@ -336,8 +336,8 @@ CHIP_ERROR CommandSender::PrepareCommand(const CommandPathParams & aCommandPathP

if (aStartDataStruct)
{
ReturnLogErrorOnFailure(invokeRequest.GetWriter()->StartContainer(TLV::ContextTag(to_underlying(CommandDataIB::Tag::kData)),
TLV::kTLVType_Structure, mDataElementContainerType));
ReturnErrorOnFailure(invokeRequest.GetWriter()->StartContainer(TLV::ContextTag(to_underlying(CommandDataIB::Tag::kData)),
TLV::kTLVType_Structure, mDataElementContainerType));
}

MoveToState(State::AddingCommand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ using namespace chip::DeviceLayer;
{ \
if (!::chip::ChipError::IsSuccess(expr)) \
{ \
LogErrorOnFailure(commandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::code)); \
CHIP_ERROR statusErr = commandObj->AddStatus(commandPath, Protocols::InteractionModel::Status::code); \
if (statusErr != CHIP_NO_ERROR) \
{ \
ChipLogError(Zcl, "%s: %" CHIP_ERROR_FORMAT, #expr, statusErr.Format()); \
} \
return true; \
} \
} while (false)
Expand Down
12 changes: 10 additions & 2 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ constexpr bool isRendezvousBypassed()

void StopEventLoop(intptr_t arg)
{
LogErrorOnFailure(chip::DeviceLayer::PlatformMgr().StopEventLoopTask());
CHIP_ERROR err = chip::DeviceLayer::PlatformMgr().StopEventLoopTask();
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "Stopping event loop: %" CHIP_ERROR_FORMAT, err.Format());
}
}

void DispatchShutDownEvent(intptr_t arg)
Expand Down Expand Up @@ -332,7 +336,11 @@ void Server::Shutdown()
{
chip::Dnssd::ServiceAdvertiser::Instance().Shutdown();
chip::app::InteractionModelEngine::GetInstance()->Shutdown();
LogErrorOnFailure(mExchangeMgr.Shutdown());
CHIP_ERROR err = mExchangeMgr.Shutdown();
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "Exchange Mgr shutdown: %" CHIP_ERROR_FORMAT, err.Format());
}
mSessions.Shutdown();
mTransports.Close();
mCommissioningWindowManager.Shutdown();
Expand Down
12 changes: 12 additions & 0 deletions src/lib/support/CodeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ constexpr inline const _T & max(const _T & a, const _T & b)
* @param[in] expr A Boolean expression to be evaluated.
* @param[in] code A value to return if @a expr is false.
*/
#if CHIP_CONFIG_ERROR_SOURCE
#define VerifyOrReturnLogError(expr, code) \
do \
{ \
Expand All @@ -318,6 +319,17 @@ constexpr inline const _T & max(const _T & a, const _T & b)
return code; \
} \
} while (false)
#else // CHIP_CONFIG_ERROR_SOURCE
#define VerifyOrReturnLogError(expr, code) \
do \
{ \
if (!(expr)) \
{ \
ChipLogError(NotSpecified, "%s:%d false: %" CHIP_ERROR_FORMAT, #expr, __LINE__, code.Format()); \
return code; \
} \
} while (false)
#endif // CHIP_CONFIG_ERROR_SOURCE

/**
* @def ReturnErrorCodeIf(expr, code)
Expand Down

0 comments on commit 980e177

Please sign in to comment.