Skip to content

Commit

Permalink
Merge pull request #82 from bugsnag/next
Browse files Browse the repository at this point in the history
Next release
  • Loading branch information
fractalwrench authored May 3, 2018
2 parents 1224f62 + e2a727f commit 41f50db
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 12 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Changelog

## TBD

## 3.1.6 (2018-05-03)
* Make preemptive copy of map filtering specified keys
[#77](https://github.com/bugsnag/bugsnag-java/pull/77)
[Leandro Aparecido](https://github.com/lehphyro)
[#77](https://github.com/bugsnag/bugsnag-java/pull/77)
* Add setter for overriding error class
[Jamie Lynch](https://github.com/fractalwrench)
[#78](https://github.com/bugsnag/bugsnag-java/pull/78)

## 3.1.5 (2018-03-08)

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=3.1.5
version=3.1.6
group=com.bugsnag

# Default properties
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/bugsnag/Exception.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
class Exception {
private Configuration config;
private Throwable throwable;
private String errorClass;

Exception(Configuration config, Throwable throwable) {
this.config = config;
this.throwable = throwable;
this.errorClass = throwable.getClass().getName();
}

@Expose
public String getErrorClass() {
return throwable.getClass().getName();
return errorClass;
}

@Expose
Expand All @@ -27,4 +29,12 @@ public String getMessage() {
public List<Stackframe> getStacktrace() {
return Stackframe.getStacktrace(config, throwable.getStackTrace());
}

public void setErrorClass(String errorClass) {
this.errorClass = errorClass;
}

public Throwable getThrowable() {
return throwable;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/bugsnag/Notifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Notifier {
private static final String NOTIFIER_NAME = "Bugsnag Java";
private static final String NOTIFIER_VERSION = "3.1.5";
private static final String NOTIFIER_VERSION = "3.1.6";
private static final String NOTIFIER_URL = "https://github.com/bugsnag/bugsnag-java";

@Expose
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/com/bugsnag/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Report {
private Configuration config;

private String apiKey;
private Throwable throwable;
private final Exception exception;
private final HandledState handledState;
private Severity severity;
private String groupingHash;
Expand All @@ -35,7 +35,7 @@ protected Report(Configuration config, Throwable throwable) {

Report(Configuration config, Throwable throwable, HandledState handledState) {
this.config = config;
this.throwable = throwable;
this.exception = new Exception(config, throwable);
this.handledState = handledState;
this.severity = handledState.getOriginalSeverity();
}
Expand All @@ -53,8 +53,9 @@ protected String getPayloadVersion() {
@Expose
protected List<Exception> getExceptions() {
List<Exception> exceptions = new ArrayList<Exception>();
exceptions.add(exception);

Throwable currentThrowable = throwable;
Throwable currentThrowable = exception.getThrowable().getCause();
while (currentThrowable != null) {
exceptions.add(new Exception(config, currentThrowable));
currentThrowable = currentThrowable.getCause();
Expand Down Expand Up @@ -117,21 +118,30 @@ public Map getMetaData() {
* @return The {@linkplain Throwable exception} which triggered this error report.
*/
public Throwable getException() {
return throwable;
return exception.getThrowable();
}

/**
* @return the class name from the exception contained in this error report.
*/
public String getExceptionName() {
return throwable.getClass().getName();
return exception.getErrorClass();
}

/**
* Sets the class name from the exception contained in this error report.
*
* @param exceptionName the error name
*/
public void setExceptionName(String exceptionName) {
exception.setErrorClass(exceptionName);
}

/**
* @return The message from the exception contained in this error report.
*/
public String getExceptionMessage() {
return throwable.getLocalizedMessage();
return exception.getThrowable().getLocalizedMessage();
}

/**
Expand Down
87 changes: 87 additions & 0 deletions src/test/java/com/bugsnag/ExceptionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.bugsnag;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import com.bugsnag.callbacks.Callback;
import com.bugsnag.delivery.Delivery;
import com.bugsnag.serialization.Serializer;

import org.junit.Before;
import org.junit.Test;

import java.util.List;

public class ExceptionTest {

private Exception exception;
private RuntimeException ogThrowable;

/**
* Initialises a config
*
* @throws Throwable if config couldn't be initialised
*/
@Before
public void setUp() throws Throwable {
Configuration config = new Configuration("api-key");
ogThrowable = new RuntimeException("Test");
exception = new Exception(config, ogThrowable);
}

@Test
public void testDefaults() throws Throwable {
assertEquals("java.lang.RuntimeException", exception.getErrorClass());
assertEquals("Test", exception.getMessage());
assertEquals(ogThrowable, exception.getThrowable());
assertFalse(exception.getStacktrace().isEmpty());
}

@Test
public void testClassOverride() throws Throwable {
exception.setErrorClass("Hello");
assertEquals("Hello", exception.getErrorClass());
assertEquals("Test", exception.getMessage());
}

@Test
public void testReportCallback() throws Throwable {
Bugsnag bugsnag = new Bugsnag("apikey");
bugsnag.setDelivery(new Delivery() {
@Override
public void deliver(Serializer serializer, Object object) {
}

@Override
public void close() {
}
});
assertTrue(bugsnag.notify(ogThrowable, new Callback() {
@Override
public void beforeNotify(Report report) {
try {
assertEquals(ogThrowable, report.getException());
assertEquals("Test", report.getExceptionMessage());
assertEquals("java.lang.RuntimeException", report.getExceptionName());

report.setExceptionName("Foo");
assertEquals("Foo", report.getExceptionName());


List<Exception> exceptions = report.getExceptions();
assertEquals(1, exceptions.size());

Exception exception = exceptions.get(0);
assertNotNull(exception);
assertEquals("Foo", exception.getErrorClass());
assertEquals("Test", exception.getMessage());
} catch (Throwable throwable) {
report.cancel();
}
}
}));
}

}

0 comments on commit 41f50db

Please sign in to comment.