Skip to content

Commit

Permalink
Fix stack trace printing (#146) (#676)
Browse files Browse the repository at this point in the history
* Fix stack trace printing (#146)

This code will print the "Caused By" and any suppressed exceptions.

* bump gauge-java -> 0.89.0

Signed-off-by: sixcorners <[email protected]>

* Update to correct bumped version

Fix build issues by updating to the correct version

Signed-off-by: Zabil Cheriya Maliackal <[email protected]>

Co-authored-by: Srikanth <[email protected]>
Co-authored-by: Zabil Cheriya Maliackal <[email protected]>
  • Loading branch information
3 people authored Apr 14, 2022
1 parent 7a5f1b2 commit c6e0512
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ gauge run specs
#### Install specific version
* Installing specific version
```
gauge install java --version 0.8.1
gauge install java --version 0.9.0
```

#### Offline installation
* Download the plugin from [Releases](https://github.com/getgauge/gauge-java/releases)
```
gauge install java --file gauge-java-0.8.1-windows.x86_64.zip
gauge install java --file gauge-java-0.9.0-windows.x86_64.zip
```

#### Build from source
Expand Down
2 changes: 1 addition & 1 deletion java.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "java",
"version": "0.8.1",
"version": "0.9.0",
"description": "Java support for gauge",
"install": {
"windows": [],
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@

<properties>
<maven.build.timestamp.format>yyyy-MM-dd</maven.build.timestamp.format>
<projectVersion>0.8.1</projectVersion>
<projectVersion>0.9.0</projectVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
Expand Down
21 changes: 9 additions & 12 deletions src/main/java/com/thoughtworks/gauge/execution/MethodExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.thoughtworks.gauge.screenshot.ScreenshotFactory;
import gauge.messages.Spec;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.util.Set;

Expand Down Expand Up @@ -54,28 +56,23 @@ private Spec.ProtoExecutionResult createFailureExecResult(long execTime, Throwab
}
}
builder.setErrorMessage(e.getCause().toString());
builder.setStackTrace(formatStackTrace(e.getCause().getStackTrace()));
builder.setStackTrace(formatStackTrace(e.getCause()));
} else {
builder.setRecoverableError(recoverable);
builder.setErrorMessage(e.toString());
builder.setStackTrace(formatStackTrace(e.getStackTrace()));
builder.setStackTrace(formatStackTrace(e));
}
builder.setExecutionTime(execTime);
return builder.build();
}

private String formatStackTrace(StackTraceElement[] stackTrace) {
if (stackTrace == null) {
private String formatStackTrace(Throwable t) {
if (t == null) {
return "";
}
StringBuilder output = new StringBuilder();
for (StackTraceElement element : stackTrace) {
if (element.getClassName().equals("sun.reflect.NativeMethodAccessorImpl")) {
break;
}
output.append(element.toString()).append("\n");
}
return output.toString();
StringWriter out = new StringWriter();
t.printStackTrace(new PrintWriter(out));
return out.toString();
}

public Spec.ProtoExecutionResult executeMethods(Set<Method> methods, Object... args) {
Expand Down

0 comments on commit c6e0512

Please sign in to comment.