Skip to content

Commit

Permalink
Add version of resolved Pkl distribution to ExecutorException (appl…
Browse files Browse the repository at this point in the history
…e#719)

* Add version of resolved Pkl distribution to `ExecutorException`

* Review comments

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>

---------

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>
  • Loading branch information
holzensp and bioball authored Oct 23, 2024
1 parent a7cc098 commit 0aa4819
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ String evaluatePath(Path modulePath, ExecutorOptions options) {
try {
return executorSpi.evaluatePath(modulePath, options.toSpiOptions());
} catch (ExecutorSpiException e) {
throw new ExecutorException(e.getMessage(), e.getCause());
throw new ExecutorException(e.getMessage(), e.getCause(), executorSpi.getPklVersion());
} finally {
currentThread.setContextClassLoader(prevContextClassLoader);
}
Expand Down
29 changes: 29 additions & 0 deletions pkl-executor/src/main/java/org/pkl/executor/ExecutorException.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,44 @@
*/
package org.pkl.executor;

import java.util.Objects;

/**
* Indicates an {@link Executor} error. {@link #getMessage()} returns a user-facing error message.
*/
public final class ExecutorException extends RuntimeException {
private final String pklVersion;

public ExecutorException(String message) {
super(message);
pklVersion = null;
}

public ExecutorException(String message, Throwable cause) {
super(message, cause);
pklVersion = null;
}

public ExecutorException(String message, Throwable cause, String version) {
super(message, cause);
pklVersion = Objects.requireNonNull(version);
}

/**
* The selected Pkl version used to evaluate the module.
*
* <p>Returns {@code null} if this exception does not originate from an underlying Pkl evaluator.
*/
public String getPklVersion() {
return pklVersion;
}

@Override
public String getMessage() {
var message = super.getMessage();
if (pklVersion == null) {
return message;
}
return message + "\nPkl version: " + pklVersion;
}
}

0 comments on commit 0aa4819

Please sign in to comment.