Skip to content

Commit

Permalink
fix(IMEX-46): kill switch enabled exception; UX changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectroNafta committed Nov 8, 2024
1 parent 47b3ef2 commit b9cdec4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions cli/bin/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,10 @@ int main(int argc, const char** argv) {
} catch (const ReadInputException& e) {
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
} catch (const etcpp::KillSwitchException& e) {
etcpp::logInfo("Kill switch enabled.");
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
} catch (const std::exception& e) {
const auto str = fmt::format("Encountered unexpected error: {}", e.what());
etcpp::logError("Encountered unexpected error: {}", e.what());
Expand Down
4 changes: 2 additions & 2 deletions go-lib/internal/apiclient/proton.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

const etKillSwitchName = "InboxImexClientOperationDisabled"

var caseFeatureFlagKillSwitchEnabled = errors.New("Due to a technical problem, we temporarily disabled the Export Tool. Check https://status.proton.me/ for updates.") //nolint:revive,gochecknoglobals,stylecheck
var errKillSwitchEnabled = errors.New("killSwitchEnabled")

type ProtonCallbacks interface {
OnNetworkRestored()
Expand Down Expand Up @@ -116,7 +116,7 @@ func (p *ProtonAPIClientBuilder) checkKillSwitch(ctx context.Context) error {

for _, feature := range featureFlagData.Toggles {
if feature.Name == etKillSwitchName && feature.Enabled {
return caseFeatureFlagKillSwitchEnabled
return errKillSwitchEnabled
}
}

Expand Down
5 changes: 5 additions & 0 deletions lib/include/etsession.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class SessionException final : public Exception {
explicit SessionException(std::string_view what) : Exception(what) {}
};

class KillSwitchException final : public Exception {
public:
explicit KillSwitchException(std::string_view what) : Exception(what) {}
};

class SessionCallback {
public:
virtual ~SessionCallback() = default;
Expand Down
11 changes: 9 additions & 2 deletions lib/lib/etsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

namespace etcpp {

const std::string killSwitchEnabledErrMsg = "killSwitchEnabled";
const std::string killSwitchEnabledMessage =
"Due to a technical problem, we temporarily disabled the Export Tool. Check https://status.proton.me/ for updates.";

Session::LoginState mapLoginState(etSessionLoginState s);

inline void mapETStatusToException(etSession* ptr, etSessionStatus status) {
Expand Down Expand Up @@ -59,9 +63,12 @@ Session::Session(const char* serverURL, const bool telemetryDisabled, const std:
char* outErr = nullptr;
mPtr = etSessionNew(serverURL, telemetryDisabled, makeCCallback(mCallbacks.get()), &outErr);
if (mPtr == nullptr) {
auto ex = SessionException(outErr);
std::string errorMessage(outErr);
etFree(outErr);
throw std::move(ex);
if (errorMessage == killSwitchEnabledErrMsg)
throw KillSwitchException(killSwitchEnabledMessage);
else
throw SessionException(errorMessage);
}
}

Expand Down

0 comments on commit b9cdec4

Please sign in to comment.