mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Add version of resolved Pkl distribution to ExecutorException (#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>
This commit is contained in:
committed by
GitHub
parent
a7cc098925
commit
0aa4819cea
@@ -226,7 +226,7 @@ final class EmbeddedExecutor implements Executor {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user