Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve S3 error handling #15

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "cloudfuse_helper.h"

// parseCloudfuseError takes in an error and trims the error down to it's most essential
// error, which from cloudfuse is the error returned between braces []
std::string parseCloudfuseError(std::string error)
{
std::size_t start = error.find_last_of('[');
if (start == std::string::npos)
{
return error;
}

std::size_t end = error.find_last_of(']');
if (end == std::string::npos)
{
return error;
}

return error.substr(start, end);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <string>

// parseCloudfuseError takes in an error and trims the error down to it's most essential
// error, which from cloudfuse is the error returned between braces []
std::string parseCloudfuseError(std::string error);
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "settings_model.h"
#include "stub_analytics_plugin_settings_ini.h"

#include "cloudfuse_helper.h"

#define NX_PRINT_PREFIX (this->logUtils.printPrefix)
#include <nx/kit/debug.h>
#include <nx/sdk/helpers/active_setting_changed_response.h>
Expand Down Expand Up @@ -282,7 +284,44 @@ Result<const ISettingsResponse *> Engine::settingsReceived()

if (dryRunRet.errCode != 0)
{
return error(ErrorCode::internalError, "Unable to dryrun with error: " + dryRunRet.output);
if (dryRunRet.output.find("Bucket Error") != std::string::npos)
{
Engine::pushPluginDiagnosticEvent(sdk::IPluginDiagnosticEvent::Level::error, "Plugin Bucket Error",
"Error with provided cloud bucket: " +
parseCloudfuseError(dryRunRet.output));
return error(ErrorCode::otherError,
"Unable to authenticate with bucket: " + parseCloudfuseError(dryRunRet.output));
}
if (dryRunRet.output.find("Credential or Endpoint Error") != std::string::npos)
{
Engine::pushPluginDiagnosticEvent(
sdk::IPluginDiagnosticEvent::Level::error, "Plugin Credential or Endpoint Error",
"Error with cloud credentials or incorrect endpoint: " + parseCloudfuseError(dryRunRet.output));
return error(ErrorCode::otherError, "Error with cloud credentials or incorrect endpoint: " +
parseCloudfuseError(dryRunRet.output));
}
if (dryRunRet.output.find("Endpoint Error") != std::string::npos)
{
Engine::pushPluginDiagnosticEvent(sdk::IPluginDiagnosticEvent::Level::error, "Plugin Endpoint Error",
"Error with provided endpoint: " + parseCloudfuseError(dryRunRet.output));
return error(ErrorCode::otherError,
"Error with provided endpoint: " + parseCloudfuseError(dryRunRet.output));
}
if (dryRunRet.output.find("Secret Error") != std::string::npos)
{
Engine::pushPluginDiagnosticEvent(sdk::IPluginDiagnosticEvent::Level::error, "Plugin Secret Error",
"Secret key provided is incorrect: " +
parseCloudfuseError(dryRunRet.output));
return error(ErrorCode::otherError,
"Secret key provided is incorrect: " + parseCloudfuseError(dryRunRet.output));
}

// Otherwise this is an error we did not prepare for
Engine::pushPluginDiagnosticEvent(sdk::IPluginDiagnosticEvent::Level::error, "Plugin Error",
"Unable to validate credentials with error: " +
parseCloudfuseError(dryRunRet.output));
return error(ErrorCode::otherError,
"Unable to validate credentials with error: " + parseCloudfuseError(dryRunRet.output));
}

#if defined(__linux__)
Expand Down