private ProcedureException noSuchFunction( QualifiedName name ) { return new ProcedureException( Status.Procedure.ProcedureNotFound, "There is no function with the name `%s` registered for this database instance. " + "Please ensure you've spelled the function name correctly and that the " + "function is properly deployed.", name ); }
if ( !isPublic( field.getModifiers() ) ) throw new ProcedureException( Status.Procedure.TypeError, "Field `%s` in record `%s` cannot be accessed. Please ensure the field is marked as `public`.", field.getName(), userClass.getSimpleName() ); throw new ProcedureException( e.status(), e, "Field `%s` in record `%s` cannot be converted to a Neo4j type: %s", field.getName(), userClass.getSimpleName(), e.getMessage() ); throw new ProcedureException( Status.Procedure.TypeError, e, "Field `%s` in record `%s` cannot be accessed: %s", field.getName(), userClass.getSimpleName(), e.getMessage() );
private ProcedureException closeAndCreateProcedureException( Throwable t ) { ProcedureException procedureException = newProcedureException( t ); try { close(); } catch ( Exception exceptionDuringClose ) { try { procedureException.addSuppressed( exceptionDuringClose ); } catch ( Throwable ignore ) { } } return procedureException; } }
@Test public void shouldThrowAnExceptionIfTheIndexDoesNotExist() { when( tokenRead.propertyKey( anyString() ) ).thenReturn( 0 ); when( tokenRead.nodeLabel( anyString() ) ).thenReturn( 0 ); when( schemaRead.index( anyInt(), any() ) ).thenReturn( IndexReference.NO_INDEX ); try { procedure.awaitIndexByPattern( ":Person(name)", TIMEOUT, TIME_UNIT ); fail( "Expected an exception" ); } catch ( ProcedureException e ) { assertThat( e.status(), is( Status.Schema.IndexNotFound ) ); } }
@Test public void shouldThrowAnExceptionIfTheIndexHasFailed() throws IndexNotFoundKernelException { when( tokenRead.nodeLabel( anyString() ) ).thenReturn( 0 ); when( tokenRead.propertyKey( anyString() ) ).thenReturn( 0 ); when( schemaRead.index( anyInt(), any() ) ).thenReturn( anyIndex ); when( schemaRead.indexGetState( any( IndexReference.class ) ) ).thenReturn( FAILED ); when( schemaRead.indexGetFailure( any( IndexReference.class ) ) ).thenReturn( Exceptions.stringify( new Exception( "Kilroy was here" ) ) ); try { procedure.awaitIndexByPattern( ":Person(name)", TIMEOUT, TIME_UNIT ); fail( "Expected an exception" ); } catch ( ProcedureException e ) { assertThat( e.status(), is( Status.Schema.IndexCreationFailed ) ); assertThat( e.getMessage(), containsString( "Kilroy was here" ) ); } }
@Test public void shouldFailNicelyWhenUnsafeAPISafeModeFunction() throws Throwable { //When List<CallableUserFunction> procList = compiler.compileFunction( FunctionWithUnsafeAPI.class); verify( log ).warn( notAvailableMessage( "org.neo4j.kernel.impl.proc.listCoolPeople" ) ); assertThat( procList.size(), equalTo( 1 ) ); try { procList.get( 0 ).apply( new BasicContext(), new AnyValue[0] ); fail(); } catch ( ProcedureException e ) { assertThat( e.getMessage(), notAvailableMessageMatcher( "org.neo4j.kernel.impl.proc.listCoolPeople" ) ); } }
@Test public void shouldThrowAnExceptionIfTheIndexWithGivenNameDoesNotExist() { when( tokenRead.propertyKey( anyString() ) ).thenReturn( 0 ); when( tokenRead.nodeLabel( anyString() ) ).thenReturn( 0 ); when( schemaRead.indexGetForName( "some index" ) ).thenReturn( IndexReference.NO_INDEX ); try { procedure.awaitIndexByName( "`some index`", TIMEOUT, TIME_UNIT ); fail( "Expected an exception" ); } catch ( ProcedureException e ) { assertThat( e.status(), is( Status.Schema.IndexNotFound ) ); } }
@Test public void shouldFailNicelyWhenUnsafeAPISafeMode() throws Throwable { //When List<CallableProcedure> procList = compiler.compileProcedure( ProcedureWithUnsafeAPI.class, null, false ); verify( log ).warn( notAvailableMessage( "org.neo4j.kernel.impl.proc.listCoolPeople" ) ); assertThat( procList.size(), equalTo( 1 ) ); try { procList.get( 0 ).apply( new BasicContext(), new Object[0], resourceTracker ); fail(); } catch ( ProcedureException e ) { assertThat( e.getMessage(), notAvailableMessageMatcher( "org.neo4j.kernel.impl.proc.listCoolPeople" ) ); } }
private ProcedureException noSuchProcedure( QualifiedName name ) { return new ProcedureException( Status.Procedure.ProcedureNotFound, "There is no procedure with the name `%s` registered for this database instance. " + "Please ensure you've spelled the procedure name correctly and that the " + "procedure is properly deployed.", name ); }
throw new ProcedureException( Status.Procedure.ProcedureRegistrationFailed, "Argument at position %d in method `%s` is missing an `@%s` annotation.%n" + "Please add the annotation, recompile the class and try again.", throw new ProcedureException( Status.Procedure.ProcedureRegistrationFailed, "Argument at position %d in method `%s` is annotated with a name,%n" + "but the name is empty, please provide a non-empty name for the argument.", throw new ProcedureException( Status.Procedure.ProcedureRegistrationFailed, "Non-default argument at position %d with name %s in method %s follows default argument. " + "Add a default value or rearrange arguments so that the non-default values comes first.", throw new ProcedureException( e.status(), "Argument `%s` at position %d in `%s` with%n" + "type `%s` cannot be converted to a Neo4j type: %s", name, i, method.getName(), param.getType().getSimpleName(), e.getMessage() );
@Test public void shouldThrowAnExceptionIfTheIndexDoesNotExist() throws SchemaRuleNotFoundException { when( tokenRead.nodeLabel( anyString() ) ).thenReturn( 0 ); when( tokenRead.propertyKey( anyString() ) ).thenReturn( 0 ); when( schemaRead.index( anyInt(), any() ) ).thenReturn( IndexReference.NO_INDEX ); try { procedure.resampleIndex( ":Person(name)" ); fail( "Expected an exception" ); } catch ( ProcedureException e ) { assertThat( e.status(), is( Status.Schema.IndexNotFound ) ); } }
@Test public void shouldFailNicelyWhenUnsafeAPISafeModeAggregationFunction() throws Throwable { //When List<CallableUserAggregationFunction> procList = compiler.compileAggregationFunction( AggregationFunctionWithUnsafeAPI.class); verify( log ).warn( notAvailableMessage( "org.neo4j.kernel.impl.proc.listCoolPeople" ) ); assertThat( procList.size(), equalTo( 1 ) ); try { procList.get(0).create( new BasicContext() ).update( new Object[]{} ); Object out = procList.get(0).create( new BasicContext() ).result(); fail(); } catch ( ProcedureException e ) { assertThat( e.getMessage(), notAvailableMessageMatcher( "org.neo4j.kernel.impl.proc.listCoolPeople" ) ); } }
private ProcedureException closeAndCreateProcedureException( Throwable t ) { ProcedureException procedureException = newProcedureException( t ); try { close(); } catch ( Exception exceptionDuringClose ) { try { procedureException.addSuppressed( exceptionDuringClose ); } catch ( Throwable ignore ) { } } return procedureException; } }
private ProcedureException noSuchFunction( int id ) { return new ProcedureException( Status.Procedure.ProcedureNotFound, "There is no function with the internal id `%d` registered for this database instance.", id ); }
if ( !isPublic( field.getModifiers() ) ) throw new ProcedureException( Status.Procedure.TypeError, "Field `%s` in record `%s` cannot be accessed. Please ensure the field is marked as `public`.", field.getName(), userClass.getSimpleName() ); throw new ProcedureException( e.status(), e, "Field `%s` in record `%s` cannot be converted to a Neo4j type: %s", field.getName(), userClass.getSimpleName(), e.getMessage() ); throw new ProcedureException( Status.Procedure.TypeError, e, "Field `%s` in record `%s` cannot be accessed: %s", field.getName(), userClass.getSimpleName(), e.getMessage() );
@Test public void shouldThrowAnExceptionIfThePropertyKeyDoesntExist() { when( tokenRead.propertyKey( "nonExistentProperty" ) ).thenReturn( -1 ); try { procedure.resampleIndex( ":Label(nonExistentProperty)" ); fail( "Expected an exception" ); } catch ( ProcedureException e ) { assertThat( e.status(), is( Status.Schema.PropertyKeyAccessFailed ) ); } }
private ProcedureException noSuchProcedure( int id ) { return new ProcedureException( Status.Procedure.ProcedureNotFound, "There is no procedure with the internal id `%d` registered for this database instance.", id ); }
throw new ProcedureException( Status.Procedure.ProcedureRegistrationFailed, "Argument at position %d in method `%s` is missing an `@%s` annotation.%n" + "Please add the annotation, recompile the class and try again.", throw new ProcedureException( Status.Procedure.ProcedureRegistrationFailed, "Argument at position %d in method `%s` is annotated with a name,%n" + "but the name is empty, please provide a non-empty name for the argument.", throw new ProcedureException( Status.Procedure.ProcedureRegistrationFailed, "Non-default argument at position %d with name %s in method %s follows default argument. " + "Add a default value or rearrange arguments so that the non-default values comes first.", throw new ProcedureException( e.status(), "Argument `%s` at position %d in `%s` with%n" + "type `%s` cannot be converted to a Neo4j type: %s", name, i, method.getName(), param.getType().getSimpleName(), e.getMessage() );
@Test public void shouldThrowAnExceptionIfTheLabelDoesntExist() { when( tokenRead.nodeLabel( "NonExistentLabel" ) ).thenReturn( -1 ); try { procedure.awaitIndexByPattern( ":NonExistentLabel(prop)", TIMEOUT, TIME_UNIT ); fail( "Expected an exception" ); } catch ( ProcedureException e ) { assertThat( e.status(), is( Status.Schema.LabelAccessFailed ) ); } }
public Object typeCheck( Object javaValue ) throws ProcedureException { if ( javaValue == null || javaClass.isInstance( javaValue ) ) { return javaValue; } throw new ProcedureException( Status.Procedure.ProcedureCallFailed, "Expected `%s` to be a `%s`, found `%s`.", javaValue, javaClass.getSimpleName(), javaValue.getClass() ); }