-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PLUGIN-1848] Error Management for File plugin Source/Sink #1912
Conversation
1e92b0c
to
4bb60cf
Compare
a2cd069
to
d25f116
Compare
3d77a35
to
a7b066a
Compare
@@ -243,7 +284,14 @@ protected ValidatingInputFormat getInputFormatForRun(BatchSourceContext context) | |||
+ "or re-create the pipeline with all required properties.", | |||
fileFormat, properties); | |||
throw new IllegalArgumentException(errorMessage, e); | |||
} catch (InstantiationException e) { | |||
context.getFailureCollector().addFailure( | |||
String.format("Could not find the '%s' input format.", fileFormat), null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could not load the input format %s
try { | ||
job = JobUtils.createInstance(); | ||
} catch (IOException e) { | ||
collector.addFailure("Failed to create job instance.", e.getMessage()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.getMessage()
is not a corrective action:
collector.addFailure(String.format("Failed to create job instance, %s: %s", e.getClass().getName(), e.getMessage()), null)
This comment applies to whole PR.
schema = schemaDetector.detectSchema(config.getPath(context), pattern, | ||
formatContext, getFileSystemProperties(null)); | ||
} catch (IOException e) { | ||
collector.addFailure("Error when trying to detect schema: " + e.getMessage(), null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
collector.addFailure(String.format("Failed to auto-detect schema, %s: %s", e.getClass().getName(), e.getMessage()), null)
@@ -243,7 +284,14 @@ protected ValidatingInputFormat getInputFormatForRun(BatchSourceContext context) | |||
+ "or re-create the pipeline with all required properties.", | |||
fileFormat, properties); | |||
throw new IllegalArgumentException(errorMessage, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please convert IllegalArgumentException
to ProgramFailureException
.
@@ -124,12 +126,17 @@ public void prepareRun(BatchSinkContext context) throws Exception { | |||
Map<String, String> outputProperties = new HashMap<>(validatingOutputFormat.getOutputFormatConfiguration()); | |||
outputProperties.putAll(getFileSystemProperties(context)); | |||
outputProperties.put(FileOutputFormat.OUTDIR, getOutputDir(context)); | |||
context.setErrorDetailsProvider(new ErrorDetailsProviderSpec(getErrorDetailsProviderClassName())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since GCSBatchSink
does not override getErrorDetailsProviderClassName()
, this will get set to null
, see here: https://github.com/data-integrations/google-cloud/blob/77e0ac8a386d12b7b55f7e9fab2b1adaa88d9a01/src/main/java/io/cdap/plugin/gcp/gcs/sink/GCSBatchSink.java#L168-L172
Please check getErrorDetailsProviderClassName
is not null
or empty
and then only set it.
similar for AbstractFileBatchSource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -97,7 +103,8 @@ private Map<String, String> getFSProperties() { | |||
try { | |||
return GSON.fromJson(fileSystemProperties, MAP_TYPE); | |||
} catch (JsonSyntaxException e) { | |||
throw new IllegalArgumentException("Unable to parse filesystem properties: " + e.getMessage(), e); | |||
throw new IllegalArgumentException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw ProgramFailureException
instead
core-plugins/src/main/java/io/cdap/plugin/batch/source/FileErrorDetailsProvider.java
Show resolved
Hide resolved
core-plugins/src/main/java/io/cdap/plugin/common/HydratorErrorDetailsProvider.java
Show resolved
Hide resolved
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Error details provided for the Snowflake |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Snowflake
?
try { | ||
fileStatus = pathFileSystem.globStatus(path); | ||
} catch (IOException e) { | ||
collector.addFailure("Failed to get file status for path " + path, e.getMessage()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use String.format
everywhere.
e.getMessage()
, is not a correctiveAction
also preserve error class name,
%s: %s, e.getClass().getName(), e.getMessage()
@@ -243,7 +284,14 @@ protected ValidatingInputFormat getInputFormatForRun(BatchSourceContext context) | |||
+ "or re-create the pipeline with all required properties.", | |||
fileFormat, properties); | |||
throw new IllegalArgumentException(errorMessage, e); | |||
} catch (InstantiationException e) { | |||
context.getFailureCollector().addFailure( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create a local variable collector = context.getFailureCollector()
and use at other places in same method.
String.format("Could not find the '%s' input format.", fileFormat), null) | ||
.withPluginNotFound(fileFormat, fileFormat, ValidatingInputFormat.PLUGIN_TYPE) | ||
.withStacktrace(e.getStackTrace()); | ||
context.getFailureCollector().getOrThrowException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw collector.getOrThrowException();
This way you wouldn't need to return null
at the end.
875e48f
to
8923a7d
Compare
* @param exception The Exception to get the error information from. | ||
* @return A ProgramFailureException with the given error information. | ||
*/ | ||
private ProgramFailureException getProgramFailureException(Exception exception, ErrorContext errorContext, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private ProgramFailureException getProgramFailureException(IllegalArgumentException exception, ErrorContext errorContext,
context.getFailureCollector().getOrThrowException(); | ||
} | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment here
"Format '%s' cannot be used because properties %s were not provided or " | ||
+ "were invalid when the pipeline was deployed. Set the format to a " | ||
+ "different value, or re-create the pipeline with all required properties.", | ||
fileFormat, properties); | ||
throw new IllegalArgumentException(errorMessage, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar comment to throw ProgramFailureException
e.getMessage()); | ||
throw ErrorUtils.getProgramFailureException( | ||
new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorMessage, errorMessage, | ||
ErrorType.SYSTEM, false, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why SYSTEM
?
8923a7d
to
bc96350
Compare
@@ -97,7 +107,12 @@ private Map<String, String> getFSProperties() { | |||
try { | |||
return GSON.fromJson(fileSystemProperties, MAP_TYPE); | |||
} catch (JsonSyntaxException e) { | |||
throw new IllegalArgumentException("Unable to parse filesystem properties: " + e.getMessage(), e); | |||
String errorMessage = String.format( | |||
"Failed to parse filesystem properties %s with message: %s", fileSystemProperties, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we please follow the same format everywhere? %s : %s", e.getClass().getName(), e.getMessage()
331d51b
to
6fb4e61
Compare
6fb4e61
to
6f4b5d8
Compare
@@ -97,7 +107,12 @@ private Map<String, String> getFSProperties() { | |||
try { | |||
return GSON.fromJson(fileSystemProperties, MAP_TYPE); | |||
} catch (JsonSyntaxException e) { | |||
throw new IllegalArgumentException("Unable to parse filesystem properties: " + e.getMessage(), e); | |||
String errorMessage = String.format( | |||
"Failed to parse filesystem properties %s with message: %s: %s", fileSystemProperties, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Failed to parse filesystem properties %s, %s: %s"
@@ -124,7 +124,7 @@ Map<String, String> getFileSystemProperties() { | |||
try { | |||
return GSON.fromJson(fileSystemProperties, MAP_STRING_STRING_TYPE); | |||
} catch (Exception e) { | |||
throw new IllegalArgumentException("Unable to parse filesystem properties: " + e.getMessage(), e); | |||
throw new IllegalArgumentException(String.format("Unable to parse filesystem properties: %s", e.getMessage()), e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Unable to parse filesystem properties, %s: %s", e.getClass().getName(), e.getMessage()
Please add a JIRA in the title |
https://cdap.atlassian.net/browse/PLUGIN-1848