Skip to content

Commit

Permalink
log full traceback
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Feb 6, 2023
1 parent e7637ce commit 531769c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void documentChangedNonBulk(DocumentEvent documentEvent) {
LineStats lineStats = WakaTime.getLineStats(document, documentEvent.getOffset());
WakaTime.appendHeartbeat(file, project, false, lineStats);
} catch(Exception e) {
WakaTime.log.error(e);
WakaTime.warnException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void run() {
}
});
} catch(Exception e) {
WakaTime.log.error(e);
WakaTime.warnException(e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/com/wakatime/intellij/plugin/CustomSaveListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void beforeDocumentSaving(Document document) {
}
WakaTime.appendHeartbeat(file, project, true, lineStats);
} catch(Exception e) {
WakaTime.log.error(e);
WakaTime.warnException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void visibleAreaChanged(VisibleAreaEvent visibleAreaEvent) {
LineStats lineStats = WakaTime.getLineStats(document, offset);
WakaTime.appendHeartbeat(file, project, false, lineStats);
} catch(Exception e) {
WakaTime.log.error(e);
WakaTime.warnException(e);
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/com/wakatime/intellij/plugin/Dependencies.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static boolean isCLIOld() {
if (output.trim().equals(cliVersion)) return false;
}
} catch (Exception e) {
WakaTime.log.warn(e);
WakaTime.warnException(e);
}
return true;
}
Expand Down Expand Up @@ -415,6 +415,7 @@ public PasswordAuthentication getPasswordAuthentication() {

} catch (MalformedURLException e) {
WakaTime.log.error("Proxy string must follow https://user:pass@host:port format: " + proxyConfig);
WakaTime.warnException(e);
}
}
}
Expand Down Expand Up @@ -538,15 +539,15 @@ private static void makeExecutable(String filePath) throws IOException {
try {
file.setExecutable(true);
} catch(SecurityException e) {
WakaTime.log.warn(e);
WakaTime.warnException(e);
}
}

private static boolean isSymLink(File filepath) {
try {
return Files.isSymbolicLink(filepath.toPath());
} catch(SecurityException e) {
WakaTime.log.warn(e);
WakaTime.warnException(e);
return false;
}
}
Expand All @@ -555,7 +556,7 @@ private static boolean isDirectory(File filepath) {
try {
return filepath.isDirectory();
} catch(SecurityException e) {
WakaTime.log.warn(e);
WakaTime.warnException(e);
return false;
}
}
Expand All @@ -569,19 +570,19 @@ public static void createSymlink(String source, String destination) {
try {
Files.createSymbolicLink(sourceLink.toPath(), new File(destination).toPath());
} catch (Exception e) {
WakaTime.log.warn(e);
WakaTime.warnException(e);
try {
Files.copy(new File(destination).toPath(), sourceLink.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (Exception ex) {
WakaTime.log.warn(ex);
WakaTime.warnException(ex);
}
}
}
} else {
try {
Files.copy(new File(destination).toPath(), sourceLink.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
WakaTime.log.warn(e);
WakaTime.warnException(e);
}
}
}
Expand Down
23 changes: 15 additions & 8 deletions src/com/wakatime/intellij/plugin/WakaTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void run() {
ApiKey apiKey = new ApiKey(project);
apiKey.promptForApiKey();
} catch(Exception e) {
log.warn(e);
warnException(e);
} catch (Throwable throwable) {
log.warn("Unable to prompt for api key because UI not ready.");
}
Expand Down Expand Up @@ -315,7 +315,7 @@ private static void sendHeartbeat(final Heartbeat heartbeat, final ArrayList<Hea
stdin.close();
} catch (IOException e) { /* ignored because wakatime-cli closes pipe after receiving \n */ }
} catch (IOException e) {
log.warn(e);
warnException(e);
}
}
if (WakaTime.DEBUG) {
Expand All @@ -334,7 +334,7 @@ private static void sendHeartbeat(final Heartbeat heartbeat, final ArrayList<Hea
log.debug("Command finished with return value: " + proc.exitValue());
}
} catch (Exception e) {
log.warn(e);
warnException(e);
if (Dependencies.isWindows() && e.toString().contains("Access is denied")) {
try {
Messages.showWarningDialog("Microsoft Defender is blocking WakaTime. Please allow " + Dependencies.getCLILocation() + " to run so WakaTime can upload code stats to your dashboard.", "Error");
Expand Down Expand Up @@ -550,7 +550,7 @@ public static void setupStatusBar() {
if (statusbar == null) return;
statusbar.updateWidget("WakaTime");
} catch (Exception e) {
log.warn(e);
warnException(e);
}
}
}
Expand Down Expand Up @@ -621,7 +621,7 @@ public static LineStats getLineStats(Document document, int offset) {
lineStats.lineNumber = document.getLineNumber(offset) + 1;
lineStats.cursorPosition = offset - document.getLineStartOffset(lineStats.lineNumber - 1) + 1;
} catch (Exception e) {
log.warn(e);
warnException(e);
}
return lineStats;
}
Expand Down Expand Up @@ -669,10 +669,10 @@ public void run() {
log.debug("Command finished with return value: " + proc.exitValue());
todayText = " " + String.join("", output);
todayTextTime = getCurrentTimestamp();
} catch (InterruptedException interruptedException) {
interruptedException.printStackTrace();
} catch (InterruptedException interruptedException) {
warnException(interruptedException);
} catch (Exception e) {
log.warn(e);
warnException(e);
if (Dependencies.isWindows() && e.toString().contains("Access is denied")) {
try {
Messages.showWarningDialog("Microsoft Defender is blocking WakaTime. Please allow " + Dependencies.getCLILocation() + " to run so WakaTime can upload code stats to your dashboard.", "Error");
Expand Down Expand Up @@ -706,6 +706,13 @@ private static String[] obfuscateKey(String[] cmds) {
return newCmds.toArray(new String[newCmds.size()]);
}

public static void warnException(Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String str = e.getMessage() + "\n" + sw.toString();
log.warn(str);
}

@NotNull
public String getComponentName() {
return "WakaTime";
Expand Down

0 comments on commit 531769c

Please sign in to comment.