/** * Make sure the <i>givenPath</i> refers to an entity under the given <i>basePath</i>. Idea is to avoid using ".." to * refer entities outside the ba * @param basePath * @param givenPath */ public static void verifyNoAccessOutsideBase(Path basePath, Path givenPath) { final String givenPathNormalized = Path.getPathWithoutSchemeAndAuthority(givenPath).toString(); final String basePathNormalized = Path.getPathWithoutSchemeAndAuthority(basePath).toString(); if (!givenPathNormalized.startsWith(basePathNormalized)) { throw UserException.permissionError() .message("Not allowed to access files outside of the source root") .addContext("Source root", basePathNormalized) .addContext("Requested to path", givenPathNormalized) .build(logger); } }
protected String meth(String methodName, boolean required) { String method = initializer.getMethod(methodName); if (method == null) { if (!required) { return ""; } long count = initializer.getCount(); Collection<String> methods = initializer.getMethodNames(); throw UserException .functionError() .message("Failure while trying use function. No body found for required method %s. Count %d, Methods that were available %s", methodName, count, methods) .addContext("FunctionClass", initializer.getClassName()) .build(logger); } return method; }
public static UserException.Builder withStatus(UserException.Builder builder, Response.Status status) { return builder.addContext(RESPONSE_STATUS+":"+status.toString()); }
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; }
@Override public void append(byte data) { if (!collect) { return; } if (currentDataPointer >= MAX_FIELD_LENGTH -1) { throw UserException .unsupportedError() .message("Trying to write something big in a column") .addContext("columnIndex", currentFieldIndex) .addContext("Limit", MAX_FIELD_LENGTH) .build(logger); } fieldBytes[currentDataPointer++] = data; }
@Override public void failed(RpcException ex) { if (!isTerminal.compareAndSet(false, true)) { logger.warn("Received multiple responses to run query request."); return; } // Although query submission failed, results might have arrived for this query. // However, the results could not be transferred to this resultListener because // there is no query id mapped to this resultListener. Look out for the warning // message from ChannelClosedHandler in the client logs. // TODO(DRILL-4586) resultsListener.submissionFailed(UserException.systemError(ex) .addContext("Query submission to SabotNode failed.") .build(logger)); }
public RelRoot expandView(ViewTable view) { final RelRoot root; try { root = DremioSqlToRelConverter.expandView(view.getPath(), view.getViewOwner(), view.getView().getSql(), view.getView().getWorkspaceSchemaPath(), sqlConverter); } catch (Exception ex) { throw UserException.planError(ex) .message("Error while expanding view %s",view.getPath()) .addContext("View SQL", view.getView().getSql()) .build(logger); } checkRowTypeConsistency(root.validatedRowType, view.getView().getRowType(sqlConverter.getCluster().getTypeFactory()), view.getPath().getSchemaPath()); return root; }
/** * 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()); } } }
/** * 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; }
public ExceptionBuilder addContext(final String value) { b.addContext(value); return this; }
@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)); } }
public ExceptionBuilder addContext(final String value, Object... args) { b.addContext(value, args); return this; }
public ExceptionBuilder addContext(final String name, final String value) { b.addContext(name, value); return this; }
private void validateWiki(CollaborationWiki wiki) { if (wiki.getEntityId() == null) { throw UserException.validationError() .message("Wiki entity id cannot be null.") .build(logger); } String text = wiki.getText(); if (text != null && text.length() > MAX_WIKI_LENGTH) { throw UserException.validationError() .message("Wiki text can not contain more than 100K characters but found [%s].", text.length()) .build(logger); } }
private static SearchFieldSorting buildSorter(final String sortColumn, final SortOrder order) { if(sortColumn == null){ return DEFAULT_SORTER; } final IndexKey key = UserIndexKeys.MAPPING.getKey(sortColumn); if(key == null){ throw UserException .functionError() .message("Unable to sort by field {}", sortColumn) .build(logger); } return key.toSortField(order); }
@Override public Iterable<ExternalReflection> getExternalReflectionByDatasetPath(List<String> datasetPath) { DatasetConfig datasetConfig; try { datasetConfig = namespaceService.get().getDataset(new NamespaceKey(datasetPath)); } catch (NamespaceException e) { throw UserException.validationError(e).build(logger); } if (datasetConfig == null) { throw UserException.validationError().message(String.format("Dataset %s not found", quotedCompound(datasetPath))).build(logger); } return externalReflectionStore.findByDatasetId(datasetConfig.getId().getId()); }
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); } }
public RelDataType toCalciteRecordType(RelDataTypeFactory factory, Set<String> fieldBlacklist){ FieldInfoBuilder builder = new FieldInfoBuilder(factory); for(Field f : this) { if(!fieldBlacklist.contains(f.getName())){ builder.add(f.getName(), CompleteType.toCalciteType(f, factory)); } } RelDataType rowType = builder.build(); if(rowType.getFieldCount() == 0){ throw UserException.dataReadError().message("Selected table has no columns.").build(logger); } return rowType; }