Search in sources :

Example 1 with NoSuchRecordException

use of org.neo4j.driver.exceptions.NoSuchRecordException in project neo4j-java-driver by neo4j.

the class AsyncTransactionIT method shouldFailSingleWithMultiRecordCursor.

@Test
void shouldFailSingleWithMultiRecordCursor() {
    AsyncTransaction tx = await(session.beginTransactionAsync());
    ResultCursor cursor = await(tx.runAsync("UNWIND ['a', 'b'] AS x RETURN x"));
    NoSuchRecordException e = assertThrows(NoSuchRecordException.class, () -> await(cursor.singleAsync()));
    assertThat(e.getMessage(), startsWith("Expected a result with a single record"));
}
Also used : ResultCursor(org.neo4j.driver.async.ResultCursor) AsyncTransaction(org.neo4j.driver.async.AsyncTransaction) NoSuchRecordException(org.neo4j.driver.exceptions.NoSuchRecordException) Test(org.junit.jupiter.api.Test)

Example 2 with NoSuchRecordException

use of org.neo4j.driver.exceptions.NoSuchRecordException in project neo4j-java-driver by neo4j.

the class AsyncResultCursorImplTest method shouldFailWhenAskedForSingleRecordButResultIsEmpty.

@Test
void shouldFailWhenAskedForSingleRecordButResultIsEmpty() {
    PullAllResponseHandler pullAllHandler = mock(PullAllResponseHandler.class);
    when(pullAllHandler.nextAsync()).thenReturn(completedWithNull());
    AsyncResultCursorImpl cursor = newCursor(pullAllHandler);
    NoSuchRecordException e = assertThrows(NoSuchRecordException.class, () -> await(cursor.singleAsync()));
    assertThat(e.getMessage(), containsString("result is empty"));
}
Also used : PullAllResponseHandler(org.neo4j.driver.internal.handlers.PullAllResponseHandler) AsyncResultCursorImpl(org.neo4j.driver.internal.cursor.AsyncResultCursorImpl) NoSuchRecordException(org.neo4j.driver.exceptions.NoSuchRecordException) Test(org.junit.jupiter.api.Test)

Example 3 with NoSuchRecordException

use of org.neo4j.driver.exceptions.NoSuchRecordException in project neo4j-java-driver by neo4j.

the class AsyncSessionIT method shouldFailSingleWithEmptyCursor.

@Test
void shouldFailSingleWithEmptyCursor() {
    ResultCursor cursor = await(session.runAsync("CREATE ()"));
    NoSuchRecordException e = assertThrows(NoSuchRecordException.class, () -> await(cursor.singleAsync()));
    assertThat(e.getMessage(), containsString("result is empty"));
}
Also used : ResultCursor(org.neo4j.driver.async.ResultCursor) NoSuchRecordException(org.neo4j.driver.exceptions.NoSuchRecordException) Test(org.junit.jupiter.api.Test)

Example 4 with NoSuchRecordException

use of org.neo4j.driver.exceptions.NoSuchRecordException in project multiverse-controller by multiverse-nms.

the class Neo4jWrapper method handleError.

private <T> void handleError(Throwable error, Handler<AsyncResult<T>> resultHandler) {
    // NoSuchRecordException
    if (error instanceof Neo4jException) {
        Neo4jException ne = (Neo4jException) error;
        String code = ne.code();
        logger.error("Neo4jException: " + code);
        String errorMessage = "INTERNAL";
        if (code.contains("NotFound")) {
            errorMessage = "NOT_FOUND";
        } else if (code.contains("DatabaseFound")) {
            errorMessage = "CONFLICT";
        } else if (code.contains("Invalid")) {
            errorMessage = "INVALID_ARGUMENTS";
        } else if (code.contains("Constraint")) {
            errorMessage = "CONFLICT";
        }
        resultHandler.handle(Future.failedFuture(errorMessage));
    } else if (error instanceof NoSuchRecordException) {
        logger.error("Neo4j NoSuchRecord: " + error.getMessage());
        resultHandler.handle(Future.failedFuture("NOT_FOUND"));
    } else {
        logger.error("Exception: " + error.getMessage());
        resultHandler.handle(Future.failedFuture("INTERNAL"));
    }
}
Also used : Neo4jException(org.neo4j.driver.exceptions.Neo4jException) NoSuchRecordException(org.neo4j.driver.exceptions.NoSuchRecordException)

Example 5 with NoSuchRecordException

use of org.neo4j.driver.exceptions.NoSuchRecordException in project neo4j-migrations by michael-simons.

the class Migrations method getLastAppliedVersion.

private Optional<MigrationVersion> getLastAppliedVersion() {
    try (Session session = context.getSchemaSession()) {
        Node lastMigration = session.readTransaction(tx -> tx.run("MATCH (l:__Neo4jMigration) WHERE coalesce(l.migrationTarget,'<default>') = coalesce($migrationTarget,'<default>') AND NOT (l)-[:MIGRATED_TO]->(:__Neo4jMigration) RETURN l", Collections.singletonMap(PROPERTY_MIGRATION_TARGET, config.getMigrationTargetIn(context).orElse(null))).single().get(0).asNode());
        String version = lastMigration.get("version").asString();
        String description = lastMigration.get("description").asString();
        return Optional.of(MigrationVersion.withValueAndDescription(version, description));
    } catch (NoSuchRecordException e) {
        return Optional.empty();
    }
}
Also used : Node(org.neo4j.driver.types.Node) NoSuchRecordException(org.neo4j.driver.exceptions.NoSuchRecordException) Session(org.neo4j.driver.Session)

Aggregations

NoSuchRecordException (org.neo4j.driver.exceptions.NoSuchRecordException)29 NotFoundException (org.structr.api.NotFoundException)19 ClientException (org.neo4j.driver.exceptions.ClientException)18 DatabaseException (org.neo4j.driver.exceptions.DatabaseException)18 ServiceUnavailableException (org.neo4j.driver.exceptions.ServiceUnavailableException)18 TransientException (org.neo4j.driver.exceptions.TransientException)18 NetworkException (org.structr.api.NetworkException)18 RetryException (org.structr.api.RetryException)18 ResultCursor (org.neo4j.driver.async.ResultCursor)14 Record (org.neo4j.driver.Record)13 RxResult (org.neo4j.driver.reactive.RxResult)8 Test (org.junit.jupiter.api.Test)6 Entity (org.neo4j.driver.types.Entity)3 Node (org.neo4j.driver.types.Node)3 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 AsyncTransaction (org.neo4j.driver.async.AsyncTransaction)2 AsyncResultCursorImpl (org.neo4j.driver.internal.cursor.AsyncResultCursorImpl)2 PullAllResponseHandler (org.neo4j.driver.internal.handlers.PullAllResponseHandler)2 Relationship (org.neo4j.driver.types.Relationship)2