Skip to content

Commit

Permalink
Improve the error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
forgedhallpass committed Jun 3, 2022
1 parent 59d6ce3 commit ccf1944
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
18 changes: 12 additions & 6 deletions src/main/java/burp/BurpExtender.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks) {
callbacks.registerContextMenuFactory(createContextMenuFactory(generalSettings, callbacks.getHelpers()));

callbacks.addSuiteTab(createConfigurationTab(generalSettings));
} catch (RuntimeException e) {
generalSettings.logError("Unexpected error", e);
} catch (Throwable e) {
JOptionPane.showMessageDialog(null, "There was an error while trying to initialize the plugin. Please check the logs.", "An error occurred", JOptionPane.ERROR_MESSAGE);
generalSettings.logError("Error while trying to initialize the plugin", e);
}
}

Expand Down Expand Up @@ -339,11 +340,16 @@ private void generateTemplate(GeneralSettings generalSettings, URL targetUrl, Re
.build();

SwingUtilities.invokeLater(() -> {
final TemplateGeneratorTabContainer templateGeneratorTabContainer = getTemplateGeneratorContainerInstance(generalSettings);
templateGeneratorTabContainer.addTab(new TemplateGeneratorTab(nucleiGeneratorSettings));
try {
final TemplateGeneratorTabContainer templateGeneratorTabContainer = getTemplateGeneratorContainerInstance(generalSettings);
templateGeneratorTabContainer.addTab(new TemplateGeneratorTab(nucleiGeneratorSettings));

if (!generalSettings.isDetachedGeneratorWindow()) {
configureEmbeddedGeneratorTab(generalSettings, templateGeneratorTabContainer);
if (!generalSettings.isDetachedGeneratorWindow()) {
configureEmbeddedGeneratorTab(generalSettings, templateGeneratorTabContainer);
}
} catch (Throwable e) {
JOptionPane.showMessageDialog(null, "There was an error while trying to complete the requested action. Please check the logs.", "An error occurred", JOptionPane.ERROR_MESSAGE);
generalSettings.logError("Error while trying to generate/show the generated template", e);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import io.projectdiscovery.nuclei.gui.settings.SettingsPanel;
import io.projectdiscovery.utils.Utils;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalTime;
Expand Down Expand Up @@ -100,7 +103,13 @@ public void logError(String content) {
}

public void logError(String content, Throwable e) {
this.errorConsumer.accept(addTimePrefix(String.format("%s:\n%s", content, e.getMessage())));
try (StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter)) {
e.printStackTrace(printWriter);
this.errorConsumer.accept(addTimePrefix(String.format("%s:\n%s", content, stringWriter)));
} catch (IOException ex) {
this.errorConsumer.accept(addTimePrefix(String.format("Error while trying to extract the stack trace: %s", ex)));
}
}

public void log(String content) {
Expand Down

0 comments on commit ccf1944

Please sign in to comment.