use of org.neo4j.commandline.admin.CommandFailed in project neo4j by neo4j.
the class DumpCommandTest method shouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock.
@Test
public void shouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock() throws Exception {
assumeFalse("We haven't found a way to reliably tests permissions on Windows", SystemUtils.IS_OS_WINDOWS);
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
StoreLocker storeLocker = new StoreLocker(fileSystem)) {
storeLocker.checkLock(databaseDirectory.toFile());
try (Closeable ignored = withPermissions(databaseDirectory.resolve(StoreLocker.STORE_LOCK_FILENAME), emptySet())) {
execute("foo.db");
fail("expected exception");
} catch (CommandFailed e) {
assertThat(e.getMessage(), equalTo("you do not have permission to dump the database -- is Neo4j " + "running as a different user?"));
}
}
}
use of org.neo4j.commandline.admin.CommandFailed in project neo4j by neo4j.
the class DumpCommandTest method shouldWrapIOExceptionsCarefulllyBecauseCriticalInformationIsOftenEncodedInTheirNameButMissingFromTheirMessage.
@Test
public void shouldWrapIOExceptionsCarefulllyBecauseCriticalInformationIsOftenEncodedInTheirNameButMissingFromTheirMessage() throws Exception {
doThrow(new IOException("the-message")).when(dumper).dump(any(), any(), any());
try {
execute("foo.db");
fail("expected exception");
} catch (CommandFailed e) {
assertThat(e.getMessage(), equalTo("unable to dump database: IOException: the-message"));
}
}
use of org.neo4j.commandline.admin.CommandFailed in project neo4j by neo4j.
the class DumpCommandTest method shouldGiveAClearErrorIfTheArchiveAlreadyExists.
@Test
public void shouldGiveAClearErrorIfTheArchiveAlreadyExists() throws Exception {
doThrow(new FileAlreadyExistsException("the-archive-path")).when(dumper).dump(any(), any(), any());
try {
execute("foo.db");
fail("expected exception");
} catch (CommandFailed e) {
assertThat(e.getMessage(), equalTo("archive already exists: the-archive-path"));
}
}
use of org.neo4j.commandline.admin.CommandFailed in project neo4j by neo4j.
the class LoadCommandTest method shouldWrapIOExceptionsCarefulllyBecauseCriticalInformationIsOftenEncodedInTheirNameButMissingFromTheirMessage.
@Test
public void shouldWrapIOExceptionsCarefulllyBecauseCriticalInformationIsOftenEncodedInTheirNameButMissingFromTheirMessage() throws IOException, IncorrectUsage, IncorrectFormat {
doThrow(new FileSystemException("the-message")).when(loader).load(any(), any());
try {
execute(null);
fail("expected exception");
} catch (CommandFailed e) {
assertThat(e.getMessage(), equalTo("unable to load database: FileSystemException: the-message"));
}
}
use of org.neo4j.commandline.admin.CommandFailed in project neo4j by neo4j.
the class UnbindFromClusterCommand method execute.
@Override
public void execute(String[] args) throws IncorrectUsage, CommandFailed {
try {
Config config = loadNeo4jConfig(homeDir, configDir, arguments.parse("database", args));
File dataDirectory = config.get(DatabaseManagementSystemSettings.data_directory);
Path pathToSpecificDatabase = config.get(DatabaseManagementSystemSettings.database_path).toPath();
Validators.CONTAINS_EXISTING_DATABASE.validate(pathToSpecificDatabase.toFile());
confirmTargetDirectoryIsWritable(pathToSpecificDatabase);
ClusterStateDirectory clusterStateDirectory = new ClusterStateDirectory(dataDirectory);
clusterStateDirectory.initialize(outsideWorld.fileSystem());
deleteClusterStateIn(clusterStateDirectory.get().toPath());
} catch (StoreLockException e) {
throw new CommandFailed("Database is currently locked. Please shutdown Neo4j.", e);
} catch (IllegalArgumentException e) {
throw new IncorrectUsage(e.getMessage());
} catch (UnbindFailureException | CannotWriteException | IOException | ClusterStateException e) {
throw new CommandFailed(e.getMessage(), e);
}
}
Aggregations