diff --git a/src/main/java/io/projectriff/invoker/ApplicationRunner.java b/src/main/java/io/projectriff/invoker/ApplicationRunner.java index 43835ee..9f73dd4 100644 --- a/src/main/java/io/projectriff/invoker/ApplicationRunner.java +++ b/src/main/java/io/projectriff/invoker/ApplicationRunner.java @@ -90,7 +90,12 @@ public Object getBean(String name) { if (containsBeanByName(name)) { return getBeanByName(name); } - return getBeanByType(name); + try { + return getBeanByType(name); + } + catch (Exception e) { + // not there + } } return null; } diff --git a/src/main/java/io/projectriff/invoker/GrpcConfiguration.java b/src/main/java/io/projectriff/invoker/GrpcConfiguration.java index 34895ed..dbd344e 100644 --- a/src/main/java/io/projectriff/invoker/GrpcConfiguration.java +++ b/src/main/java/io/projectriff/invoker/GrpcConfiguration.java @@ -75,6 +75,10 @@ public void start() throws IOException { try { Function, Flux> function = catalog.lookup(Function.class, functions.getFunctionName()); + if (function == null) { + throw new IllegalStateException( + "No such function: " + functions.getFunctionName()); + } this.server = ServerBuilder.forPort(this.port) .addService(new JavaFunctionInvokerServer(function, this.mapper, inspector.getInputType(function), diff --git a/src/test/java/io/projectriff/invoker/ExceptionConverterTests.java b/src/test/java/io/projectriff/invoker/ExceptionConverterTests.java index d7fc925..c09c620 100644 --- a/src/test/java/io/projectriff/invoker/ExceptionConverterTests.java +++ b/src/test/java/io/projectriff/invoker/ExceptionConverterTests.java @@ -113,6 +113,7 @@ private void checkStatus(Throwable cause, Status.Code expectedCode) { assertThat(s.getCause()).isEqualTo(cause); } + @SuppressWarnings("serial") private static class TestException extends Throwable { TestException(String message) { super(message); diff --git a/src/test/java/io/projectriff/invoker/GrpcIsolatedTests.java b/src/test/java/io/projectriff/invoker/GrpcIsolatedTests.java index 78ecded..30ca29f 100644 --- a/src/test/java/io/projectriff/invoker/GrpcIsolatedTests.java +++ b/src/test/java/io/projectriff/invoker/GrpcIsolatedTests.java @@ -67,6 +67,14 @@ public void fluxFunctionNotIsolated() throws Exception { + "?handler=io.projectriff.functions.FluxDoubler"); } + @Test + public void nonExistentFunction() throws Exception { + expected.expect(BeanCreationException.class); + SpringApplication.run(JavaFunctionInvokerApplication.class, "--server.port=0", + "--grpc.port=" + port, "--function.uri=file:target/test-classes" + + "?handler=io.projectriff.functions.NotHere"); + } + @Test public void fluxFunction() throws Exception { runner.run("--server.port=0", "--grpc.port=" + port, @@ -151,6 +159,13 @@ public void appClassPath() throws Exception { assertThat(result).contains("10"); } + @Test(expected = IllegalStateException.class) + public void nonExistentFunctionWithMain() throws Exception { + runner.run("--server.port=0", "--grpc.port=" + port, + "--function.uri=app:classpath?" + "handler=notThere&" + + "main=io.projectriff.functions.FunctionApp"); + } + @Test public void mainClassBeanName() throws Exception { runner.run("--server.port=0", "--grpc.port=" + port,