Skip to content

Commit 049f192

Browse files
authored
Merge pull request #57 from HubSpot/ariofrio/propagate-call-stack
Use `Throwable` as the exception cause in `unwrapOrElseThrow`
2 parents 4317f58 + 6cdd07a commit 049f192

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

algebra/src/main/java/com/hubspot/algebra/Result.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,13 @@ public <X extends Throwable> SUCCESS_TYPE unwrapOrElseThrow(
105105
}
106106

107107
public SUCCESS_TYPE unwrapOrElseThrow() {
108-
return unwrapOrElseThrow(err -> new IllegalStateException(err.toString()));
108+
return unwrapOrElseThrow(err -> {
109+
if (err instanceof Throwable) {
110+
return new IllegalStateException((Throwable) err);
111+
} else {
112+
return new IllegalStateException(err.toString());
113+
}
114+
});
109115
}
110116

111117
public SUCCESS_TYPE expect(String message) {
@@ -125,7 +131,13 @@ public <X extends Throwable> ERROR_TYPE unwrapErrOrElseThrow(
125131
}
126132

127133
public ERROR_TYPE unwrapErrOrElseThrow() {
128-
return unwrapErrOrElseThrow(ok -> new IllegalStateException(ok.toString()));
134+
return unwrapErrOrElseThrow(ok -> {
135+
if (ok instanceof Throwable) {
136+
return new IllegalStateException((Throwable) ok);
137+
} else {
138+
return new IllegalStateException(ok.toString());
139+
}
140+
});
129141
}
130142

131143
public ERROR_TYPE expectErr(String message) {

0 commit comments

Comments
 (0)