private static void addContextAndThrow(Builder userExceptionBuilder, List<String> context) { if (context != null && !context.isEmpty()) { Preconditions.checkArgument(context.size() % 2 == 0); ListIterator<String> iterator = context.listIterator(); while (iterator.hasNext()) { userExceptionBuilder.addContext(iterator.next(), iterator.next()); } } throw userExceptionBuilder.build(logger); }
private static UserException.Builder addResponseInfo(UserException.Builder builder, Response response) { try { builder.addContext("Response Status", response.getStatusInfo().getStatusCode()); builder.addContext("Response Reason", response.getStatusInfo().getReasonPhrase()); String string = CharStreams.toString(new InputStreamReader((InputStream) response.getEntity())); builder.addContext("Response Body", string); } catch(Exception ex){ logger.warn("Failure while decoding exception", ex); } return builder; }
public TableInstance(TableSignature sig, List<Object> params) { super(); if (params.size() != sig.params.size()) { throw UserException.parseError() .message( "should have as many params (%d) as signature (%d)", params.size(), sig.params.size()) .addContext("table", sig.name) .build(logger); } this.sig = sig; this.params = unmodifiableList(params); }
public static UserException.Builder planError(String query, Exception ex) { UserException.Builder b = UserException.planError(ex) .addContext(SQL_QUERY_CONTEXT, query); // CalciteContextException alters the error message including the start/end positions // we need to extract the original error message and add the remaining information as context if (ex instanceof CalciteContextException) { CalciteContextException cce = (CalciteContextException) ex; b.message(cce.getMessage()) .addContext(START_LINE_CONTEXT, cce.getPosLine()) .addContext(START_COLUMN_CONTEXT, cce.getPosColumn()) .addContext(END_LINE_CONTEXT, cce.getEndPosLine()) .addContext(END_COLUMN_CONTEXT, cce.getEndPosColumn()); } return b; }
public static UserException.Builder withStatus(UserException.Builder builder, Response.Status status) { return builder.addContext(RESPONSE_STATUS+":"+status.toString()); }
/** * Creates an OUT_OF_MEMORY error with a prebuilt message * * @param cause exception that will be wrapped inside a memory error * @return user exception builder */ public static Builder memoryError(final Throwable cause) { final Builder b = builder(DremioPBError.ErrorType.OUT_OF_MEMORY, cause) .message(MEMORY_ERROR_MSG); if (cause != null) { b.addContext(cause.getMessage()); } return b; }
@Override public void interrupted(final InterruptedException ex) { if (!isTerminal.compareAndSet(false, true)) { logger.warn("Received multiple responses to run query request."); return; } // TODO(DRILL-4586) resultsListener.submissionFailed(UserException.systemError(ex) .addContext("The client had been asked to wait as the SabotNode is potentially being over-utilized." + " But the client was interrupted while waiting.") .build(logger)); } }
/** * Add the memory usage of the root allocator and all of its children to an exception */ public void addUsageToExceptionContext(UserException.Builder b) { // NB: allocator name already printed in each allocator's toString() b.addContext(toString().trim()); // in DEBUG mode, children are already printed as part of the allocator's toString() if (!BaseAllocator.isDebug()) { for (String childAllocatorName : children.keySet()) { b.addContext(" ", children.get(childAllocatorName).toString().trim()); } } }
public ExceptionBuilder addContext(final String value, Object... args) { b.addContext(value, args); return this; }
public ExceptionBuilder addContext(final String value) { b.addContext(value); return this; }
public ExceptionBuilder addContext(final String name, final String value) { b.addContext(name, value); return this; }
@Override public void checkCancel() { if (cancelFlag.isCancelRequested()) { UserException.Builder builder = UserException.planError() .message("Query was cancelled because planning time exceeded %d seconds", cancelFlag.getTimeoutInSecs()); if (phase != null) { builder = builder.addContext("Planner Phase", phase.description); } throw builder.build(logger); } super.checkCancel(); } }
public static UserException.Builder parseError(String query, SqlParseException ex) { final SqlParserPos pos = ex.getPos(); if (pos == null) { return UserException .parseError(ex) .addContext(SQL_QUERY_CONTEXT, query); } else { // Calcite convention is to return column and line numbers as 1-based inclusive positions. return addParseContext(UserException.parseError(ex), query, pos); } }
UserException.Builder addContext(UserException.Builder builder){ if(target != null){ builder.addContext("Request: " + target.getUri()); } for(ContextInfo i : contexts){ builder.addContext(i.name, String.format(i.message, i.values)); } return builder; }
private static <T extends CompleteWork> void verify(final List<NodeEndpoint> endpoints, final List<T> units, final boolean condition, final String msg, Object... args) { if (!condition) { throw UserException.resourceError() .message(msg, args) .addContext("endpoints %s", endpoints) .addContext("workunits %s", units) .build(logger); } } }
private static UserException.Builder addParseContext(UserException.Builder builder, String query, SqlParserPos pos){ // Calcite convention is to return column and line numbers as 1-based inclusive positions. return builder.addContext(SQL_QUERY_CONTEXT, query) .addContext(START_LINE_CONTEXT, pos.getLineNum()) .addContext(START_COLUMN_CONTEXT, pos.getColumnNum()) .addContext(END_LINE_CONTEXT, pos.getEndLineNum()) .addContext(END_COLUMN_CONTEXT, pos.getEndColumnNum()); }
private UserException userExceptionWithDiagnosticInfo(final Throwable t, final int count) { return UserException.dataReadError(t) .message("Failed to populate partition column values") .addContext("Partition value characteristics", populators != null ? Joiner.on(",").join(populators) : "null") .addContext("Number of rows trying to populate", count) .build(logger); }
private UserException.Builder withContextParameters(UserException.Builder uexBuilder) { uexBuilder.addContext("minDiskSpace", minDiskSpace); uexBuilder.addContext("minDiskSpacePercentage", minDiskSpacePercentage); uexBuilder.addContext("healthCheckInterval", healthCheckInterval); return uexBuilder; }
public SpillFile getSpillFile(String fileName) throws RuntimeException { try { final SpillDirectory spillDirectory = spillService.getSpillSubdir(id); return new SpillFile(spillDirectory.getFileSystem(), new Path(spillDirectory.getSpillDirPath(), fileName)); } catch (UserException e) { throw UserException.dataWriteError(e) .addContext("for %s spill id %s", caller, id) .addContext("Caller", caller) .build(logger); } }
@Override public void checkCancel() { if (cancelFlag.isCancelRequested()) { UserException.Builder builder = UserException.planError() .message("Query was cancelled because planning time exceeded %d seconds", cancelFlag.getTimeoutInSecs()); if (phase != null) { builder = builder.addContext("Planner Phase", phase.description); } throw builder.build(logger); } super.checkCancel(); }