Fix forcing of VmValue during error rendering (#1629)
This commit is contained in:
1 parent
c2652e0722
commit
bfda4cc8c8
4 files changed
+92
-7
No files matched your search
+4
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,6 +25,7 @@ import org.pkl.core.runtime.BaseModule;
|
||||
import org.pkl.core.runtime.VmClass;
|
||||
import org.pkl.core.runtime.VmDynamic;
|
||||
import org.pkl.core.runtime.VmListing;
|
||||
import org.pkl.core.runtime.VmUtils;
|
||||
|
||||
@ImportStatic(BaseModule.class)
|
||||
public abstract class GeneratorElementNode extends GeneratorMemberNode {
|
||||
@@ -63,6 +64,7 @@ public abstract class GeneratorElementNode extends GeneratorMemberNode {
|
||||
@SuppressWarnings("unused")
|
||||
void fallback(VirtualFrame frame, Object parent, ObjectData data) {
|
||||
CompilerDirectives.transferToInterpreter();
|
||||
throw exceptionBuilder().evalError("objectCannotHaveElement", parent).build();
|
||||
var parentClass = parent instanceof VmClass ? (VmClass) parent : VmUtils.getClass(parent);
|
||||
throw exceptionBuilder().evalError("objectCannotHaveElement", parentClass).build();
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,14 @@ import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.stream.*;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.pkl.core.runtime.VmValue;
|
||||
import org.pkl.core.runtime.VmValueRenderer;
|
||||
|
||||
public final class ErrorMessages {
|
||||
private ErrorMessages() {}
|
||||
|
||||
private static final VmValueRenderer renderer = VmValueRenderer.singleLine(Integer.MAX_VALUE);
|
||||
|
||||
public static String create(String messageName, @Nullable Object... args) {
|
||||
var locale = Locale.getDefault();
|
||||
String errorMessage =
|
||||
@@ -33,7 +37,18 @@ public final class ErrorMessages {
|
||||
if (args.length == 0) return errorMessage;
|
||||
|
||||
var formatter = new MessageFormat(errorMessage, locale);
|
||||
return formatter.format(args);
|
||||
// TODO: we render VmValues here with VmValueRenderer, but that's not enough to properly
|
||||
// render all kinds of values, like Pkl Strings, for example
|
||||
@Nullable Object[] actualArgs = new @Nullable Object[args.length];
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
var arg = args[i];
|
||||
if (arg instanceof VmValue) {
|
||||
actualArgs[i] = renderer.render(arg);
|
||||
} else {
|
||||
actualArgs[i] = arg;
|
||||
}
|
||||
}
|
||||
return formatter.format(actualArgs);
|
||||
}
|
||||
|
||||
public static String createIndented(String messageName, String indent, @Nullable Object... args) {
|
||||
|
||||
Reference in new issue
Block a user