Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Console break on error in batch mode #1692

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions console/src/main/java/com/arcadedb/console/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void interactiveMode() throws IOException {
}

try {
if (!parse(line, false))
if (!parse(line, false, false))
return;
} catch (final Exception e) {
// IGNORE (ALREADY PRINTED)
Expand Down Expand Up @@ -175,16 +175,13 @@ public static void execute(final String[] args) throws IOException {
final Console console = new Console();

try {
if (batchMode) {
// BATCH MODE
console.parse(commands.toString(), true);
console.parse("exit", true);
} else {
// INTERACTIVE MODE
if (console.parse(commands.toString(), true))
if (console.parse(commands.toString(), true, batchMode)) { // COMMANDLINE ARGUMENT COMMANDS
if (batchMode) { // BATCH MODE
console.executeClose();
} else { // INTERACTIVE MODE
console.interactiveMode();
}
}

} finally {
// FORCE THE CLOSING
console.close();
Expand Down Expand Up @@ -223,7 +220,7 @@ public BasicDatabase getDatabase() {
return databaseProxy;
}

private boolean execute(final String line) throws IOException {
private boolean execute(final String line) throws IOException, RuntimeException {
try {

if (line == null)
Expand Down Expand Up @@ -601,8 +598,7 @@ public void onError(Exception exception) {
try {
resultSet = databaseProxy.command(language, line);
} catch (Exception e) {
outputError(e);
return;
throw e;
}

if (transactionBatchSize > 0) {
Expand Down Expand Up @@ -696,7 +692,7 @@ private void executeLoad(final String fileName) throws IOException {
while (bufferedReader.ready()) {
final String line = FileUtils.decodeFromFile(bufferedReader.readLine());

parse(line, true);
parse(line, true, false);

++executedLines;
byteReadFromFile += line.length() + 1;
Expand Down Expand Up @@ -724,11 +720,15 @@ private void executeLoad(final String fileName) throws IOException {
flushOutput();
}

public boolean parse(final String line) throws IOException {
return parse(line, false);
public boolean parse(final String line) throws IOException, RuntimeException {
return parse(line, false, true);
}

public boolean parse(final String line, final boolean printCommand) throws IOException {
public boolean parse(final String line, final boolean printCommand) throws IOException, RuntimeException {
return parse(line, printCommand, true);
}

public boolean parse(final String line, final boolean printCommand, final boolean batchMode) throws IOException, RuntimeException {

final ParsedLine parsedLine = parser.parse(line, 0);

Expand All @@ -739,8 +739,13 @@ public boolean parse(final String line, final boolean printCommand) throws IOExc
if (printCommand)
output(3, getPrompt() + w);

if (!execute(w))
return false;
try {
if (!execute(w))
return false;
} catch (final IOException | RuntimeException e) {
if (batchMode)
throw e;
}
}
return true;
}
Expand Down
Loading