Skip to content

Commit c45f4fc

Browse files
Merge pull request cdapio#16047 from cdapio/CDAP-21207
[CDAP-21207] Add error classification during input/output format initialization
2 parents 425b0ce + f752e5a commit c45f4fc

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

cdap-app-templates/cdap-etl/cdap-etl-core/src/main/java/io/cdap/cdap/etl/batch/DelegatingInputFormat.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ protected final InputFormat<K, V> getDelegate(Configuration conf) {
8585
}
8686
return inputFormat;
8787
} catch (Exception e) {
88-
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategoryEnum.PLUGIN),
88+
throw new RuntimeException(
8989
String.format("Unable to instantiate delegate input format class '%s'.",
90-
delegateClassName), e.getMessage(), ErrorType.SYSTEM, false, e);
90+
delegateClassName), e);
9191
}
9292
}
9393
}

cdap-app-templates/cdap-etl/cdap-etl-core/src/main/java/io/cdap/cdap/etl/batch/DelegatingOutputFormat.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ protected final OutputFormat<K, V> getDelegate(Configuration conf) {
8585
}
8686
return outputFormat;
8787
} catch (Exception e) {
88-
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategoryEnum.PLUGIN),
88+
throw new RuntimeException(
8989
String.format("Unable to instantiate delegate output format class '%s'.",
90-
delegateClassName), e.getMessage(), ErrorType.SYSTEM, false, e);
90+
delegateClassName), e);
9191
}
9292
}
9393
}

cdap-app-templates/cdap-etl/cdap-etl-core/src/main/java/io/cdap/cdap/etl/common/ErrorDetails.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616

1717
package io.cdap.cdap.etl.common;
1818

19+
import com.google.common.base.Throwables;
20+
import io.cdap.cdap.api.exception.FailureDetailsProvider;
1921
import io.cdap.cdap.api.exception.ProgramFailureException;
2022
import io.cdap.cdap.api.exception.WrappedStageException;
2123
import io.cdap.cdap.etl.api.exception.ErrorContext;
2224
import io.cdap.cdap.etl.api.exception.ErrorDetailsProvider;
2325
import io.cdap.cdap.etl.api.exception.ErrorPhase;
2426
import io.cdap.cdap.etl.api.exception.NoopErrorDetailsProvider;
27+
import java.util.List;
2528
import org.apache.hadoop.conf.Configuration;
2629
import org.slf4j.Logger;
2730
import org.slf4j.LoggerFactory;
@@ -70,10 +73,34 @@ public static WrappedStageException handleException(Exception e, String stageNam
7073
ErrorDetailsProvider errorDetailsProvider, ErrorPhase phase) {
7174
ProgramFailureException exception = null;
7275

73-
if (!(e instanceof ProgramFailureException)) {
76+
if (!(isFailureDetailsProviderInCausalChain(e))) {
7477
exception = errorDetailsProvider == null ? null :
75-
errorDetailsProvider.getExceptionDetails(e, new ErrorContext(phase));
78+
errorDetailsProvider.getExceptionDetails(e, new ErrorContext(phase));
79+
}
80+
WrappedStageException wrappedStageException = getWrappedStageExceptionFromCausalChain(e);
81+
if (wrappedStageException != null) {
82+
return wrappedStageException;
7683
}
7784
return new WrappedStageException(exception == null ? e : exception, stageName);
7885
}
86+
87+
public static boolean isFailureDetailsProviderInCausalChain(Throwable e) {
88+
List<Throwable> causalChain = Throwables.getCausalChain(e);
89+
for (Throwable cause : causalChain) {
90+
if (cause instanceof FailureDetailsProvider) {
91+
return true;
92+
}
93+
}
94+
return false;
95+
}
96+
97+
public static WrappedStageException getWrappedStageExceptionFromCausalChain(Throwable e) {
98+
List<Throwable> causalChain = Throwables.getCausalChain(e);
99+
for (Throwable cause : causalChain) {
100+
if (cause instanceof WrappedStageException) {
101+
return (WrappedStageException) cause;
102+
}
103+
}
104+
return null;
105+
}
79106
}

0 commit comments

Comments
 (0)