Skip to content

Commit

Permalink
log userDefinedException without expression
Browse files Browse the repository at this point in the history
  • Loading branch information
brig committed Feb 6, 2025
1 parent 34c53f3 commit c099d10
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void noStacktraceForUserDefinedExceptionFromExpression() throws Exception
}

// error
assertLog(runtime.lastLog(), ".*" + quote("(concord.yaml): Error @ line: 3, col: 7. while evaluating expression '${userDefinedExceptionTask.exception('BOOM')}': BOOM") + ".*");
assertLog(runtime.lastLog(), ".*" + quote("(concord.yaml): Error @ line: 3, col: 7. BOOM") + ".*");

// no single exception message
assertNoLog(runtime.lastLog(), quote("BOOM"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ public void testScriptErrorBlock() throws Exception {
.build());

byte[] log = run();
assertLog(log, ".*error occurred: java.lang.RuntimeException: Error: this is an error.*");
assertLog(log, ".*" + quote("(concord.yml): Error @ line: 3, col: 7. Error: this is an error") + ".*");
}

@Test
Expand Down Expand Up @@ -1344,7 +1344,7 @@ public void testThrowExpression() throws Exception {
run();
fail("exception expected");
} catch (Exception e) {
assertEquals("while evaluating expression '${items.stream().filter(i -> i == 42).findFirst().orElseGet(() -> throw('42 not found'))}': 42 not found", e.getMessage());
assertEquals("42 not found", e.getMessage());
}
}

Expand Down Expand Up @@ -1466,7 +1466,7 @@ public void testExpressionThrowUserDefinedError() throws Exception {
} catch (Exception e) {
// ignore
}
assertLog(runtime.lastLog(), ".*" + Pattern.quote("[ERROR] (concord.yml): Error @ line: 3, col: 7. while evaluating expression '${faultyTask.fail('BOOM')}': BOOM"));
assertLog(runtime.lastLog(), ".*" + Pattern.quote("[ERROR] (concord.yml): Error @ line: 3, col: 7. BOOM"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ public FunctionMapper getFunctionMapper() {
} catch (MethodNotFoundException e) {
throw new UserDefinedException(exceptionPrefix(expr) + e.getMessage());
} catch (UserDefinedException e) {
throw new UserDefinedException(e.getMessage());
throw e;
} catch (javax.el.ELException e) {
if (e.getCause() instanceof com.sun.el.parser.ParseException pe) {
throw new WrappedException("while parsing expression '" + expr + "': ", pe);
}

var lastElException = ExceptionUtils.findLastException(e, javax.el.ELException.class);
if (lastElException.getCause() instanceof Exception ee) {
if (lastElException.getCause() instanceof UserDefinedException ue) {
throw ue;
} else if (e.getCause() instanceof com.sun.el.parser.ParseException pe) {
throw new UserDefinedException("while parsing expression '" + expr + "': " + pe.getMessage());
} else if (lastElException.getCause() instanceof Exception ee) {
throw new WrappedException(exceptionPrefix(expr), ee);
}
throw lastElException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
import com.oracle.truffle.js.scriptengine.GraalJSEngineFactory;
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
import com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders;
import com.walmartlabs.concord.runtime.v2.runner.vm.WrappedException;
import com.walmartlabs.concord.runtime.v2.sdk.Context;
import com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration;
import com.walmartlabs.concord.runtime.v2.sdk.UserDefinedException;
import com.walmartlabs.concord.sdk.Constants;
import org.graalvm.polyglot.Engine;
import org.graalvm.polyglot.HostAccess;
Expand Down Expand Up @@ -100,11 +101,11 @@ public ScriptResult eval(Context context, String language, Reader input, Map<Str
return scriptResult;
} catch (ScriptException e) {
if (e.getCause() instanceof PolyglotException) {
throw new RuntimeException(e.getCause().getMessage());
throw new UserDefinedException(e.getCause().getMessage());
}
throw new RuntimeException(e.getMessage());
throw new UserDefinedException(e.getMessage());
} catch (Exception e) {
throw new RuntimeException(e);
throw new WrappedException(e);
}
}

Expand Down Expand Up @@ -143,8 +144,8 @@ private org.graalvm.polyglot.Context.Builder getGraalEngineContextBuilder(Map<St
Optional<Integer> esVersion = Arrays.stream(GRAAL_ES_VERSIONS)
.filter(it -> it.equals(value))
.findFirst();
if (!esVersion.isPresent()) {
throw new RuntimeException("unsupported esVersion: " + value.toString());
if (esVersion.isEmpty()) {
throw new UserDefinedException("unsupported esVersion: " + value.toString());
}
ctx.option("js.ecmascript-version", esVersion.get().toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -24,6 +24,7 @@
import com.walmartlabs.concord.policyengine.PolicyEngine;
import com.walmartlabs.concord.policyengine.TaskRule;
import com.walmartlabs.concord.runtime.v2.runner.TaskResultService;
import com.walmartlabs.concord.runtime.v2.sdk.UserDefinedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -58,7 +59,7 @@ public void onEvent(TaskCallEvent event) {
result.getDeny().forEach(d -> log.error("Task call '{}' is forbidden by the task policy {}", event.taskName(), d.getRule()));

if (!result.getDeny().isEmpty()) {
throw new RuntimeException("Found forbidden tasks");
throw new UserDefinedException("Found forbidden tasks");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.Serial;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;

public class JoinCommand<T extends Step> extends StepCommand<T> {

Expand Down Expand Up @@ -89,6 +90,7 @@ protected void execute(Runtime runtime, State state, ThreadId threadId) {
if (!failed.isEmpty() && !anyReady) {
throw new ParallelExecutionException(failed.stream()
.map(state::clearThreadError)
.filter(Objects::nonNull)
.toList());
}

Expand Down

0 comments on commit c099d10

Please sign in to comment.