Skip to content

Commit

Permalink
improved logging on oauth2 failure
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Aug 3, 2024
1 parent d827df2 commit 28ff940
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
18 changes: 14 additions & 4 deletions src/auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,37 +309,47 @@ int Auth::PerformAction(const AuthAction p_AuthAction)
scriptPath + " " + ((p_AuthAction == Generate) ? "-g" : "-r") + " > " + outPath + " 2>&1";

int status = system(command.c_str());
const std::string output = Util::ReadFile(outPath);
if (WIFEXITED(status) && (WEXITSTATUS(status) == 0))
{
LOG_DEBUG((p_AuthAction == Generate) ? "oauth2 generate ok" : "oauth2 refresh ok");
UpdateExpiryTime();
if (!output.empty())
{
LOG_DEBUG("%s", output.c_str());
}
}
else if (WIFEXITED(status))
{
LOG_WARNING((p_AuthAction == Generate) ? "oauth2 generate failed (%d): %s"
: "oauth2 refresh failed (%d): %s",
WEXITSTATUS(status), command.c_str());
std::string output = Util::ReadFile(outPath);

// stderr is logged to terminal before ui started, otherwise to log file
std::cerr << output << "\n";
std::cerr << output;
if (WEXITSTATUS(status) == 7)
{
std::string msg = "try setup: nmail -d " + Util::GetApplicationDir() + " -s " + m_Auth;
LOG_WARNING("%s", msg.c_str());
}
}
else if (WIFSIGNALED(status))
{
LOG_WARNING((p_AuthAction == Generate) ? "oauth2 generate killed %d"
: "oauth2 refresh killed %d",
WTERMSIG(status));
std::cerr << output;
}
else if (WIFSTOPPED(status))
{
LOG_WARNING((p_AuthAction == Generate) ? "oauth2 generate stopped %d"
: "oauth2 refresh stopped %d",
WSTOPSIG(status));
std::cerr << output;
}
else if (WIFCONTINUED(status))
{
LOG_WARNING((p_AuthAction == Generate) ? "oauth2 generate continued"
: "oauth2 refresh continued");
std::cerr << output;
}

Util::DeleteFile(outPath);
Expand Down
2 changes: 1 addition & 1 deletion src/nmail.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH NMAIL "1" "August 2024" "nmail 5.1.6" "User Commands"
.TH NMAIL "1" "August 2024" "nmail 5.1.7" "User Commands"
.SH NAME
nmail \- ncurses mail
.SH SYNOPSIS
Expand Down
3 changes: 2 additions & 1 deletion src/oauth2nmail
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def show_help():
print(" 4 http request network error")
print(" 5 http request returned non-200")
print(" 6 access token not available")
print(" 7 refresh token not available")
print(" 130 keyboard interrupt (ctrl-c)")
print("")
print("Examples:")
Expand Down Expand Up @@ -340,7 +341,7 @@ def refresh(provider, client_id, client_secret, token_store):
refresh_token = tokens["refresh_token"]
else:
sys.stderr.write("refresh_token not set in " + token_store + "\n")
return 1
return 7

# use refresh code to request new access token
refrParams = {}
Expand Down
2 changes: 1 addition & 1 deletion src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "version.h"

#define NMAIL_VERSION "5.1.6"
#define NMAIL_VERSION "5.1.7"

std::string Version::GetBuildOs()
{
Expand Down

0 comments on commit 28ff940

Please sign in to comment.