/** * Deserialize the rawAdditionalContext from a UserException into a new AdditionalExceptionContext. * * @param ex A UserException containing serialized AdditionalExceptionContext data. * @return A new AdditionalExceptionContext of the serialized type. */ public static InvalidMetadataErrorContext fromUserException(UserException ex) { Preconditions.checkState(ex.getErrorType() == ErrorType.INVALID_DATASET_METADATA, "exception type mismatch"); return JsonAdditionalExceptionContext.fromUserException(InvalidMetadataErrorContext.class, ex); } }
public static List<QueryError> of(UserException e) { switch(e.getErrorType()) { case PARSE: case PLAN: case VALIDATION: return ImmutableList.of(new QueryError(e.getMessage(), rangeOf(e))); default: return ImmutableList.of(); } }
@Override public Response toResponse(UserException exception) { final String errorMessage = exception.getErrorType() == ErrorType.SYSTEM ? SYSTEM_ERROR_MSG : exception.getOriginalMessage(); return Response.status(getStatus(exception)) .entity(new ErrorMessageWithContext( errorMessage, removeStatus(exception.getContextStrings()), sendStackTrace ? GenericErrorMessage.printStackTrace(exception): null )) .type(APPLICATION_JSON_TYPE) .build(); }
public void bad(String passwd, String err) throws Exception { try { SimpleUserService.validatePassword(passwd); fail("Password '" + passwd + "' should not be accepted."); } catch (UserException e) { assertEquals("Expected a VALIDATION error but got " + e.getErrorType(), ErrorType.VALIDATION, e.getErrorType()); assertTrue("Unexpected error message", e.getOriginalMessage().contains(err)); } }
@Test public void testOnMessageIOException() throws IOException { try { getResponse(new IOException()); fail("Expected UserException/IOException"); } catch(UserException e) { // Expected assertEquals(ErrorType.IO_EXCEPTION, e.getErrorType()); assertSame(IOException.class, e.getCause().getClass()); } } }
@Test public void testOnMessageIOException() throws IOException { try { getResponse(new IOException()); fail("Was expecting UserException/IOException"); } catch (UserException e) { assertEquals(ErrorType.IO_EXCEPTION, e.getErrorType()); assertSame(IOException.class, e.getCause().getClass()); } } }
@Test public void testOnMessageFileNotFound() throws IOException { try { getResponse(new FileNotFoundException("Where is the file?")); fail("Was expecting UserException/FileNotFoundException"); } catch(UserException e) { assertEquals(ErrorType.IO_EXCEPTION, e.getErrorType()); assertSame(FileNotFoundException.class, e.getCause().getClass()); assertEquals("Where is the file?", e.getCause().getMessage()); } }
@Test public void testOnMessageIOException() throws IOException { try { getResponse(TEST_PATH_STRING, new IOException()); fail("Was expecting UserException/IOException"); } catch(UserException e) { assertEquals(ErrorType.IO_EXCEPTION, e.getErrorType()); assertSame(IOException.class, e.getCause().getClass()); } }
@Test public void testOnMessageIOException() throws IOException { try { getResponse(true, new IOException()); fail("Was expecting UserException/IOException"); } catch (UserException e) { assertEquals(ErrorType.IO_EXCEPTION, e.getErrorType()); assertSame(IOException.class, e.getCause().getClass()); } } }
@Test public void testOnMessageFileNotFound() throws IOException { try { getResponse(0L, 4096, new FileNotFoundException("Where is the file?")); fail("Was expecting UserException/FileNotFoundException"); } catch(UserException e) { assertEquals(ErrorType.IO_EXCEPTION, e.getErrorType()); assertSame(FileNotFoundException.class, e.getCause().getClass()); assertEquals("Where is the file?", e.getCause().getMessage()); } }
@Test public void testOnMessageIOException() throws IOException { try { getResponse(0L, 4096, new IOException("Something happened")); fail("Was expecting UserException/IOException"); } catch(UserException e) { assertEquals(ErrorType.IO_EXCEPTION, e.getErrorType()); assertSame(IOException.class, e.getCause().getClass()); assertEquals("Something happened", e.getCause().getMessage()); } } }
@Test public void testOnMessageFileNotFound() throws IOException { try { getResponse(TEST_PATH_STRING, new FileNotFoundException("Where is the file?")); fail("Was expecting UserException/FileNotFoundException"); } catch(UserException e) { assertEquals(ErrorType.IO_EXCEPTION, e.getErrorType()); assertSame(FileNotFoundException.class, e.getCause().getClass()); assertEquals("Where is the file?", e.getCause().getMessage()); } }
@Test public void testOnMessageFileNotFound() throws IOException { try { getResponse(true, new FileNotFoundException("Where is the file?")); fail("Was expecting UserException/FileNotFoundException"); } catch(UserException e) { assertEquals(ErrorType.IO_EXCEPTION, e.getErrorType()); assertSame(FileNotFoundException.class, e.getCause().getClass()); assertEquals("Where is the file?", e.getCause().getMessage()); } }
@Test public void testOnMessageFileNotFound() throws IOException { try { getResponse(new FileNotFoundException("Where is the file?")); fail("Expected UserException/FileNoFoundExpection"); } catch(UserException e) { // Expected assertEquals(ErrorType.IO_EXCEPTION, e.getErrorType()); assertSame(FileNotFoundException.class, e.getCause().getClass()); assertEquals("Where is the file?", e.getCause().getMessage()); } }
@Test public void testOnMessageIOException() throws IOException { try { getResponse(FsPermission.getDirDefault(), new IOException()); fail("Was expecting UserException/IOException"); } catch (UserException e) { assertEquals(ErrorType.IO_EXCEPTION, e.getErrorType()); assertSame(IOException.class, e.getCause().getClass()); } } }
@Test public void testOnMessageFileNotFound() throws IOException { try { getResponse(FsPermission.getDirDefault(), new FileNotFoundException("Where is the file?")); fail("Was expecting UserException/FileNotFoundException"); } catch(UserException e) { assertEquals(ErrorType.IO_EXCEPTION, e.getErrorType()); assertSame(FileNotFoundException.class, e.getCause().getClass()); assertEquals("Where is the file?", e.getCause().getMessage()); } }
@Test public void testNonSupportedSchemaChange() throws Exception { // field2 changes from int to map // original schema [field1=bit, field2=int] // new schema [field1=bit, field2=map, field3=int] List<ValueVector> original = Arrays.<ValueVector>asList(bitVector("field1"), intVector("field2")); List<ValueVector> updated = Arrays.asList(bitVector("field1"), structVector("field2"), intVector("field3")); try { checkSchemaChange(original, updated); } catch (UserException ex) { assertEquals(ErrorType.SCHEMA_CHANGE, ex.getErrorType()); } }
@Test public void testInvalidIsTimestampPattern() throws Exception { try { test("SELECT IS_TIMESTAMP(\"time\", 'yummy') FROM cp.\"/is_time.json\""); fail("Query expected to fail"); } catch (UserException uex) { assertEquals(ErrorType.FUNCTION, uex.getErrorType()); assertEquals("Failure parsing the formatting string at column 1 of: yummy", uex.getOriginalMessage()); } }
@Test public void testInvalidIsDatePattern() throws Exception { try { test("SELECT IS_DATE(\"date\", 'yummy') FROM cp.\"/is_date.json\""); fail("Query expected to fail"); } catch (UserException uex) { assertEquals(ErrorType.FUNCTION, uex.getErrorType()); assertEquals("Failure parsing the formatting string at column 1 of: yummy", uex.getOriginalMessage()); } }
@Test public void testInvalidIsTimePattern() throws Exception { try { test("SELECT IS_TIME(\"time\", 'yummy') FROM cp.\"/is_time.json\""); fail("Query expected to fail"); } catch (UserException uex) { assertEquals(ErrorType.FUNCTION, uex.getErrorType()); assertEquals("Failure parsing the formatting string at column 1 of: yummy", uex.getOriginalMessage()); } }