/** * Errors a set of tuples. * * @param tuple The tuple to error. * @param error */ private void handleError(Tuple tuple, MetronError error) { collector.ack(tuple); ErrorUtils.handleError(collector, error); }
protected void handleError(String sensorType, byte[] originalMessage, Tuple tuple, Throwable ex, OutputCollector collector) { MetronError error = new MetronError() .withErrorType(Constants.ErrorType.PARSER_ERROR) .withThrowable(ex) .withSensorType(Collections.singleton(sensorType)) .addRawMessage(originalMessage); ErrorUtils.handleError(collector, error); }
protected void handleError(String key, JSONObject rawMessage, String subGroup, JSONObject enrichedMessage, Exception e) { LOG.error("[Metron] Unable to enrich message: {}", rawMessage, e); if (key != null) { collector.emit(enrichmentType, new Values(key, enrichedMessage, subGroup)); } MetronError error = new MetronError() .withErrorType(Constants.ErrorType.ENRICHMENT_ERROR) .withThrowable(e) .addRawMessage(rawMessage); ErrorUtils.handleError(collector, error); }
.withThrowable(e) .addRawMessage(message); ErrorUtils.handleError(collector, error); collector.ack(tuple);
@Test public void handleErrorShouldEmitAndReportError() throws Exception { Throwable e = new Exception("error"); MetronError error = new MetronError().withMessage("error message").withThrowable(e); OutputCollector collector = mock(OutputCollector.class); ErrorUtils.handleError(collector, error); verify(collector, times(1)).emit(eq(Constants.ERROR_STREAM), argThat(new MetronErrorJSONMatcher(error.getJSONObject()))); verify(collector, times(1)).reportError(any()); } }
.withMessage("Unable to find SensorEnrichmentConfig for sourceType: " + sourceType) .addRawMessage(rawMessage); ErrorUtils.handleError(collector, metronError); continue; .withErrorFields(new HashSet() {{ add(field); }}) .addRawMessage(rawMessage); ErrorUtils.handleError(collector, metronError); continue;
.filter(result -> result) .count(); parserRunnerResults.getErrors().forEach(error -> ErrorUtils.handleError(collector, error));
@Override public void execute(Tuple tuple) { JSONObject message = null; try { message = (JSONObject) messageGetStrategy.get(tuple); handler.write(sensorType, tuple, message, configuration, messageGetStrategy); if(!handler.handleAck()) { collector.ack(tuple); } } catch (Throwable e) { MetronError error = new MetronError() .withErrorType(errorType) .withThrowable(e) .withSensorType(Collections.singleton(sensorType)) .addRawMessage(message); ErrorUtils.handleError(collector, error); collector.ack(tuple); } }
.withThrowable(t.getValue()) .addRawMessage(t.getKey()); ErrorUtils.handleError(collector, error); .withThrowable(e) .addRawMessage(message); ErrorUtils.handleError(collector, error);