Skip to content

Commit

Permalink
Throw cast error even when in SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghislain Fourny committed Apr 18, 2024
1 parent 24d9170 commit 6e86b10
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
16 changes: 16 additions & 0 deletions src/main/java/org/rumbledb/api/SequenceOfItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ public boolean hasNext() {
RumbleException ex = new CastException(e.getMessage(), ExceptionMetadata.EMPTY_METADATA);
ex.initCause(e);
throw ex;
} catch (SparkRuntimeException e) {
if (e.getMessage().contains("CAST_INVALID_INPUT")) {
RumbleException ex = new CastException(e.getMessage(), ExceptionMetadata.EMPTY_METADATA);
ex.initCause(e);
throw ex;
} else {
throw e;
}
} catch (UnsupportedOperationException e) {
RumbleException ex = new CastException(e.getMessage(), ExceptionMetadata.EMPTY_METADATA);
ex.initCause(e);
Expand Down Expand Up @@ -140,6 +148,14 @@ public JavaRDD<Item> getAsRDD() {
RumbleException ex = new UnexpectedTypeException(e.getMessage(), ExceptionMetadata.EMPTY_METADATA);
ex.initCause(e);
throw ex;
} catch (SparkRuntimeException e) {
if (e.getMessage().contains("CAST_INVALID_INPUT")) {
RumbleException ex = new CastException(e.getMessage(), ExceptionMetadata.EMPTY_METADATA);
ex.initCause(e);
throw ex;
} else {
throw e;
}
} catch (UnsupportedOperationException e) {
RumbleException ex = new UnexpectedTypeException(e.getMessage(), ExceptionMetadata.EMPTY_METADATA);
ex.initCause(e);
Expand Down
41 changes: 25 additions & 16 deletions src/main/java/org/rumbledb/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

import org.apache.commons.io.IOUtils;
import org.apache.spark.SparkException;
import org.apache.spark.SparkRuntimeException;
import org.rumbledb.config.RumbleRuntimeConfiguration;
import org.rumbledb.exceptions.CastException;
import org.rumbledb.exceptions.ExceptionMetadata;
import org.rumbledb.exceptions.OurBadException;
import org.rumbledb.exceptions.RumbleException;
Expand Down Expand Up @@ -149,23 +151,22 @@ private static void handleException(Throwable ex, boolean showErrorInfo) {
ex.printStackTrace();
}
System.exit(-42);
} else {
System.err.println(
"We are very embarrassed, because an error has occured that we did not anticipate 🙈: "
+ ex.getMessage()
);
System.err.println(
"We would like to investigate this and make sure to fix it. We would be very grateful if you could contact us or file an issue on GitHub with your query."
);
System.err.println("Link: https://github.com/RumbleDB/rumble/issues");
System.err.println(
"For more debug info (e.g., so you can communicate it to us), please try again using --show-error-info yes in your command line."
);
if (showErrorInfo) {
ex.printStackTrace();
}
System.exit(-42);
}
System.err.println(
"We are very embarrassed, because an error has occured that we did not anticipate 🙈: "
+ ex.getMessage()
);
System.err.println(
"We would like to investigate this and make sure to fix it. We would be very grateful if you could contact us or file an issue on GitHub with your query."
);
System.err.println("Link: https://github.com/RumbleDB/rumble/issues");
System.err.println(
"For more debug info (e.g., so you can communicate it to us), please try again using --show-error-info yes in your command line."
);
if (showErrorInfo) {
ex.printStackTrace();
}
System.exit(-42);
}
}

Expand All @@ -187,6 +188,14 @@ public static Throwable unboxException(Throwable ex) {
ExceptionMetadata.EMPTY_METADATA
);
}
if (ex instanceof SparkRuntimeException) {
if (ex.getMessage().contains("CAST_INVALID_INPUT")) {
RumbleException nex = new CastException(ex.getMessage(), ExceptionMetadata.EMPTY_METADATA);
ex.initCause(ex);
return nex;
}
// general message.
}
return ex;
}
return new OurBadException("A null exception was returned.");
Expand Down

0 comments on commit 6e86b10

Please sign in to comment.