Skip to content

Commit

Permalink
calling abort instead
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshGandhi-AWS committed Oct 3, 2023
1 parent f781e6d commit 4d6addc
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ void shutdown()
}
#endif
LoggerFactory::getLoggerInstance()->shutdown();
cout << "AWS IoT Device Client must abort execution, reason: ST shutdown";
exit(EXIT_SUCCESS);
}

Expand All @@ -165,7 +166,7 @@ void shutdown()
*
* @param reason the reason why the abort is happening
*/
void deviceClientAbort(const string &reason)
void deviceClientAbort(const string &reason, int exitCode)
{
if (resourceManager != NULL)
{
Expand All @@ -175,7 +176,7 @@ void deviceClientAbort(const string &reason)
LoggerFactory::getLoggerInstance()->shutdown();
cout << "AWS IoT Device Client must abort execution, reason: " << reason << endl;
cout << "Please check the AWS IoT Device Client logs for more information" << endl;
exit(EXIT_FAILURE);
exit(exitCode);
}

void attemptConnection()
Expand All @@ -193,7 +194,7 @@ void attemptConnection()
"IoT credentials, "
"configuration and/or certificate policy. ***",
DC_FATAL_ERROR);
deviceClientAbort("Failed to establish MQTT connection due to credential/configuration error");
deviceClientAbort("Failed to establish MQTT connection due to credential/configuration error", EXIT_FAILURE);
return true;
}
else if (SharedCrtResourceManager::SUCCESS == connectionStatus)
Expand All @@ -212,7 +213,7 @@ void attemptConnection()
catch (const std::exception &e)
{
LOGM_ERROR(TAG, "Error attempting to connect: %s", e.what());
deviceClientAbort("Failure from attemptConnection");
deviceClientAbort("Failure from attemptConnection", EXIT_FAILURE);
}
}

Expand Down Expand Up @@ -251,7 +252,7 @@ namespace Aws
TAG,
"Stopping instance of secure tunneling component to close tunnel thread",
feature->getName().c_str());
shutdown();
deviceClientAbort("Stopping instance of secure tunneling component to close tunnel thread", EXIT_SUCCESS);
#endif
break;
}
Expand Down Expand Up @@ -295,7 +296,7 @@ namespace Aws
TAG,
"*** %s: Aborting program due to unrecoverable feature error! ***",
DeviceClient::DC_FATAL_ERROR);
deviceClientAbort(feature->getName() + " encountered an error");
deviceClientAbort(feature->getName() + " encountered an error", EXIT_FAILURE);
#endif
}
};
Expand All @@ -317,7 +318,7 @@ int main(int argc, char *argv[])
TAG,
"*** %s: AWS IoT Device Client must abort execution, reason: Invalid configuration ***",
DC_FATAL_ERROR);
deviceClientAbort("Invalid configuration");
deviceClientAbort("Invalid configuration", EXIT_FAILURE);
}

if (!LoggerFactory::reconfigure(config.config) &&
Expand Down Expand Up @@ -346,7 +347,7 @@ int main(int argc, char *argv[])
if (!init(argc, argv))
{
LOGM_ERROR(TAG, "*** %s: An instance of Device Client is already running.", DC_FATAL_ERROR);
deviceClientAbort("An instance of Device Client is already running.");
deviceClientAbort("An instance of Device Client is already running.", EXIT_FAILURE);
}
#endif

Expand All @@ -368,7 +369,7 @@ int main(int argc, char *argv[])
if (!resourceManager.get()->initialize(config.config, features))
{
LOGM_ERROR(TAG, "*** %s: Failed to initialize AWS CRT SDK.", DC_FATAL_ERROR);
deviceClientAbort("Failed to initialize AWS CRT SDK");
deviceClientAbort("Failed to initialize AWS CRT SDK", EXIT_FAILURE);
}

#if !defined(EXCLUDE_FP) && !defined(DISABLE_MQTT)
Expand Down Expand Up @@ -396,7 +397,7 @@ int main(int argc, char *argv[])
"Please verify your AWS IoT credentials, "
"configuration, Fleet Provisioning Template, claim certificate and policy used. ***",
DC_FATAL_ERROR);
deviceClientAbort("Fleet provisioning failed");
deviceClientAbort("Fleet provisioning failed", EXIT_FAILURE);
}
resourceManager->disconnect();
}
Expand All @@ -408,7 +409,7 @@ int main(int argc, char *argv[])
"*** %s: Fleet Provisioning configuration is enabled but feature is not compiled into binary.",
DC_FATAL_ERROR);
deviceClientAbort("Invalid configuration. Fleet Provisioning configuration is enabled but feature is not "
"compiled into binary.");
"compiled into binary.", EXIT_FAILURE);
}
#endif

Expand All @@ -427,7 +428,7 @@ int main(int argc, char *argv[])
TAG,
"*** %s: Secure Element configuration is enabled but feature is not compiled into binary.",
DC_FATAL_ERROR);
deviceClientAbort("Invalid configuration");
deviceClientAbort("Invalid configuration", EXIT_FAILURE);
}
else
{
Expand All @@ -441,7 +442,7 @@ int main(int argc, char *argv[])
"*** %s: Secure Element configuration is enabled but feature is not compiled into binary.",
DC_FATAL_ERROR);
deviceClientAbort(
"Invalid configuration. Secure Element configuration is enabled but feature is not compiled into binary.");
"Invalid configuration. Secure Element configuration is enabled but feature is not compiled into binary.", EXIT_FAILURE);
}
#endif

Expand All @@ -465,7 +466,7 @@ int main(int argc, char *argv[])
TAG,
"*** %s: Config Shadow configuration is enabled but feature is not compiled into binary.",
DC_FATAL_ERROR);
deviceClientAbort("Invalid configuration");
deviceClientAbort("Invalid configuration", EXIT_FAILURE);
}
#endif

Expand All @@ -489,7 +490,7 @@ int main(int argc, char *argv[])
LOGM_ERROR(
TAG, "*** %s: Jobs configuration is enabled but feature is not compiled into binary.", DC_FATAL_ERROR);
deviceClientAbort(
"Invalid configuration. Config Shadow configuration is enabled but feature is not compiled into binary.");
"Invalid configuration. Config Shadow configuration is enabled but feature is not compiled into binary.", EXIT_FAILURE);
}
#endif

Expand All @@ -515,7 +516,7 @@ int main(int argc, char *argv[])
"*** %s: Secure Tunneling configuration is enabled but feature is not compiled into binary.",
DC_FATAL_ERROR);
deviceClientAbort("Invalid configuration. Secure Tunneling configuration is enabled but feature is not "
"compiled into binary.");
"compiled into binary.", EXIT_FAILURE);
}
#endif

Expand All @@ -541,7 +542,7 @@ int main(int argc, char *argv[])
"*** %s: Device Defender configuration is enabled but feature is not compiled into binary.",
DC_FATAL_ERROR);
deviceClientAbort(
"Invalid configuration. Device Defender configuration is enabled but feature is not compiled into binary.");
"Invalid configuration. Device Defender configuration is enabled but feature is not compiled into binary.", EXIT_FAILURE);
}
#endif

Expand All @@ -567,7 +568,7 @@ int main(int argc, char *argv[])
"*** %s: Sample Shadow configuration is enabled but feature is not compiled into binary.",
DC_FATAL_ERROR);
deviceClientAbort(
"Invalid configuration. Sample Shadow configuration is enabled but feature is not compiled into binary.");
"Invalid configuration. Sample Shadow configuration is enabled but feature is not compiled into binary.", EXIT_FAILURE);
}
#endif

Expand All @@ -593,7 +594,7 @@ int main(int argc, char *argv[])
"*** %s: PubSub sample configuration is enabled but feature is not compiled into binary.",
DC_FATAL_ERROR);
deviceClientAbort(
"Invalid configuration. PubSub sample configuration is enabled but feature is not compiled into binary.");
"Invalid configuration. PubSub sample configuration is enabled but feature is not compiled into binary.", EXIT_FAILURE);
}
#endif

Expand All @@ -619,7 +620,7 @@ int main(int argc, char *argv[])
"*** %s: Sensor Publish configuration is enabled but feature is not compiled into binary.",
DC_FATAL_ERROR);
deviceClientAbort(
"Invalid configuration. Sensor Publish configuration is enabled but feature is not compiled into binary.");
"Invalid configuration. Sensor Publish configuration is enabled but feature is not compiled into binary.", EXIT_FAILURE);
}
#endif

Expand Down

0 comments on commit 4d6addc

Please sign in to comment.