Skip to content

Commit 38c4802

Browse files
committed
finally able to replicate #1558
work in progress and greatly improved error logging for config js failures
1 parent 1baef70 commit 38c4802

File tree

8 files changed

+46
-8
lines changed

8 files changed

+46
-8
lines changed

karate-core/src/main/java/com/intuit/karate/core/ScenarioEngine.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ private JsValue executeJsValue(Value function, Object... args) {
12561256
return JS.execute(function, args);
12571257
} catch (Exception e) {
12581258
String jsSource = function.getSourceLocation().getCharacters().toString();
1259-
KarateException ke = JsEngine.fromJsEvalException(jsSource, e);
1259+
KarateException ke = JsEngine.fromJsEvalException(jsSource, e, null);
12601260
setFailedReason(ke);
12611261
throw ke;
12621262
}
@@ -1266,7 +1266,7 @@ public Variable evalJs(String js) {
12661266
try {
12671267
return new Variable(JS.eval(js));
12681268
} catch (Exception e) {
1269-
KarateException ke = JsEngine.fromJsEvalException(js, e);
1269+
KarateException ke = JsEngine.fromJsEvalException(js, e, null);
12701270
setFailedReason(ke);
12711271
throw ke;
12721272
}

karate-core/src/main/java/com/intuit/karate/core/ScenarioRuntime.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.intuit.karate.RuntimeHook;
3131
import com.intuit.karate.ScenarioActions;
3232
import com.intuit.karate.debug.DebugThread;
33+
import com.intuit.karate.graal.JsEngine;
3334
import com.intuit.karate.http.ResourceType;
3435
import com.intuit.karate.shell.StringLogAppender;
3536

@@ -293,8 +294,8 @@ private void evalConfigJs(String js, String displayName) {
293294
Map<String, Object> map = engine.getOrEvalAsMap(fun);
294295
engine.setVariables(map);
295296
} catch (Exception e) {
296-
String message = scenario.getDebugInfo() + "\n" + displayName + "\n" + e.getMessage();
297-
error = new KarateException(message, e);
297+
String message = ">> " + scenario.getDebugInfo() + "\n>> " + displayName + " failed\n>> " + e.getMessage();
298+
error = JsEngine.fromJsEvalException(js, e, message);
298299
stopped = true;
299300
configFailed = true;
300301
}

karate-core/src/main/java/com/intuit/karate/graal/JsEngine.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,14 @@ public Value evalWith(Set<String> names, Function<String, Object> getVariable, S
202202
return function.execute(JsValue.fromJava(arg));
203203
}
204204

205-
public static KarateException fromJsEvalException(String js, Exception e) {
205+
public static KarateException fromJsEvalException(String js, Exception e, String message) {
206206
// do our best to make js error traces informative, else thrown exception seems to
207207
// get swallowed by the java reflection based method invoke flow
208208
StackTraceElement[] stack = e.getStackTrace();
209209
StringBuilder sb = new StringBuilder();
210+
if (message != null) {
211+
sb.append(message).append('\n');
212+
}
210213
sb.append(">>>> js failed:\n");
211214
List<String> lines = StringUtils.toStringLines(js);
212215
int index = 0;
@@ -221,7 +224,7 @@ public static KarateException fromJsEvalException(String js, Exception e) {
221224
if (line.startsWith("<js>") || i > 5) {
222225
break;
223226
}
224-
}
227+
}
225228
return new KarateException(sb.toString());
226229
}
227230

karate-core/src/main/java/com/intuit/karate/template/KarateEngineContext.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public JsValue evalGlobal(String src) {
8787
try {
8888
return jsEngine.eval(src);
8989
} catch (Exception e) {
90-
throw JsEngine.fromJsEvalException(src, e);
90+
throw JsEngine.fromJsEvalException(src, e, null);
9191
}
9292
}
9393

@@ -96,7 +96,7 @@ public JsValue evalLocal(String src, boolean returnValue) {
9696
Value value = jsEngine.evalWith(getVariableNames(), this::getVariable, src, returnValue);
9797
return new JsValue(value);
9898
} catch (Exception e) {
99-
throw JsEngine.fromJsEvalException(src, e);
99+
throw JsEngine.fromJsEvalException(src, e, null);
100100
}
101101
}
102102

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.intuit.karate.core.parajava;
2+
3+
import com.intuit.karate.Results;
4+
import com.intuit.karate.Runner;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class ParallelJavaTest {
10+
11+
// @Test
12+
public void testParallel() {
13+
Results results = Runner.path("classpath:com/intuit/karate/core/parajava/parallel-java.feature")
14+
.configDir("classpath:com/intuit/karate/core/parajava")
15+
.parallel(5);
16+
assertEquals(0, results.getFailCount(), results.getErrorMessages());
17+
}
18+
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function karateConfig() {
2+
return karate.callSingle('setup.feature');
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Feature:
2+
3+
Scenario: test 1
4+
* match Hello.sayHello("foo") == "hello foo"
5+
6+
Scenario: test 2
7+
* match Hello.sayHello("foo") == "hello foo"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@ignore
2+
Feature:
3+
4+
Scenario:
5+
* def Hello = Java.type('com.intuit.karate.core.parallel.Hello')

0 commit comments

Comments
 (0)