use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class DumpCommandIT method shouldGiveAClearErrorIfTheArchiveAlreadyExists.
@Test
void shouldGiveAClearErrorIfTheArchiveAlreadyExists() throws Exception {
doThrow(new FileAlreadyExistsException("the-archive-path")).when(dumper).dump(any(), any(), any(), any(), any());
CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo"));
assertEquals("Archive already exists: the-archive-path", commandFailed.getMessage());
}
use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class DumpCommandIT method shouldGiveAClearMessageIfTheDatabaseDoesntExist.
@Test
void shouldGiveAClearMessageIfTheDatabaseDoesntExist() {
CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("bobo"));
assertEquals("Database does not exist: bobo", commandFailed.getMessage());
}
use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class DiagnosticsReportCommandTest method allHasToBeOnlyClassifier.
@Test
void allHasToBeOnlyClassifier() throws Exception {
String[] args = { "all", "logs", "tx" };
DiagnosticsReportCommand diagnosticsReportCommand = new DiagnosticsReportCommand(ctx);
CommandLine.populateCommand(diagnosticsReportCommand, args);
CommandFailedException incorrectUsage = assertThrows(CommandFailedException.class, diagnosticsReportCommand::execute);
assertEquals("If you specify 'all' this has to be the only classifier. Found ['logs','tx'] as well.", incorrectUsage.getMessage());
}
use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class DumpCommand method execute.
@Override
public void execute() {
var databaseName = database.name();
Path archive = buildArchivePath(databaseName, to.toAbsolutePath());
var memoryTracker = EmptyMemoryTracker.INSTANCE;
Config config = CommandHelpers.buildConfig(ctx, allowCommandExpansion);
DatabaseLayout databaseLayout = Neo4jLayout.of(config).databaseLayout(databaseName);
try {
Validators.CONTAINS_EXISTING_DATABASE.validate(databaseLayout.databaseDirectory());
} catch (IllegalArgumentException e) {
throw new CommandFailedException("Database does not exist: " + databaseName, e);
}
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
if (fileSystem.fileExists(databaseLayout.file(StoreUpgrader.MIGRATION_DIRECTORY))) {
throw new CommandFailedException("Store migration folder detected - A dump can not be taken during a store migration. Make sure " + "store migration is completed before trying again.");
}
} catch (IOException e) {
wrapIOException(e);
}
try (Closeable ignored = LockChecker.checkDatabaseLock(databaseLayout)) {
checkDbState(databaseLayout, config, memoryTracker);
dump(databaseLayout, archive);
} catch (FileLockException e) {
throw new CommandFailedException("The database is in use. Stop database '" + databaseName + "' and try again.", e);
} catch (IOException e) {
wrapIOException(e);
} catch (CannotWriteException e) {
throw new CommandFailedException("You do not have permission to dump the database.", e);
}
}
use of org.neo4j.cli.CommandFailedException in project neo4j by neo4j.
the class LoadCommandTest method shouldThrowIfTheArchiveFormatIsInvalid.
@Test
void shouldThrowIfTheArchiveFormatIsInvalid() throws IOException, IncorrectFormat {
doThrow(IncorrectFormat.class).when(loader).load(any(), any());
CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo", archive));
assertThat(commandFailed.getMessage()).contains(archive.toString());
assertThat(commandFailed.getMessage()).contains("valid Neo4j archive");
}
Aggregations