Skip to content

Commit

Permalink
Merge pull request #6427 from jakewins/3.0-procedure-errors
Browse files Browse the repository at this point in the history
Better message on exceptions with null messages in procedures.
  • Loading branch information
pontusmelke committed Feb 15, 2016
2 parents bff283f + c972950 commit 0714942
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,14 @@ public RawIterator<Object[], ProcedureException> apply( Context ctx, Object[] in
}
catch ( Throwable throwable )
{
String message = throwable.getMessage();
if( message == null )
{
message = String.format("`%s` was thrown when invoking the procedure.",
throwable.getClass().getName());
}
throw new ProcedureException( Status.Procedure.CallFailed, throwable,
"Failed to invoke procedure `%s`: %s", signature, throwable.getMessage() );
"Failed to invoke procedure `%s`: %s", signature.name(), message );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,21 @@ public void shouldAllowOverridingProcedureNameWithoutNamespace() throws Throwabl
assertEquals("singleName", proc.signature().name().toString() );
}

@Test
public void shouldGiveHelpfulErrorOnNullMessageException() throws Throwable
{
// Given
CallableProcedure proc = compile( ProcedureThatThrowsNullMsgExceptionAtInvocation.class ).get( 0 );

// Expect
exception.expect( ProcedureException.class );
exception.expectMessage( "Failed to invoke procedure `org.neo4j.kernel.impl.proc.throwsAtInvocation`: " +
"`java.lang.IndexOutOfBoundsException` was thrown when invoking the procedure." );

// When
proc.apply( new BasicContext(), new Object[0] );
}

public static class MyOutputRecord
{
public String name;
Expand Down Expand Up @@ -374,6 +389,26 @@ public Stream<MyOutputRecord> test( )
}
}

public static class ProcedureThatThrowsNullMsgExceptionAtInvocation
{
@Procedure
public Stream<MyOutputRecord> throwsAtInvocation( )
{
throw new IndexOutOfBoundsException();
}
}

public static class ProcedureThatThrowsNullMsgExceptionMidStream
{
@Procedure
public Stream<MyOutputRecord> throwsInStream( )
{
return Stream.generate( () -> {
throw new IndexOutOfBoundsException();
});
}
}

public static class PrivateConstructorProcedure
{
private PrivateConstructorProcedure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void shouldGetHelpfulErrorOnProcedureThrowsException() throws Exception
quotedJson( "{ 'statements': [ { 'statement': 'CALL org.neo4j.harness.procThatThrows' } ] }" ) );

String error = response.get( "errors" ).get( 0 ).get( "message" ).asText();
assertEquals( "Failed to invoke procedure `org.neo4j.harness.procThatThrows() :: (someNumber :: INTEGER?)`: This is an exception", error );
assertEquals( "Failed to invoke procedure `org.neo4j.harness.procThatThrows`: This is an exception", error );
}
}
}

0 comments on commit 0714942

Please sign in to comment.