Skip to content
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

Merged
merged 1 commit into from
Jan 24, 2025

Conversation

Amit-CloudSufi
Copy link
Contributor

@Amit-CloudSufi Amit-CloudSufi commented Jan 17, 2025

https://cdap.atlassian.net/browse/PLUGIN-1848

[
  {
    "stageName": "File",
    "errorCategory": "Plugin-'File'",
    "errorReason": "Input path /Users/pusaini/wsf/cdap/env/group_by_test_data_1/data.csv does not exist",
    "errorMessage": "Input path /Users/pusaini/wsf/cdap/env/group_by_test_data_1/data.csv does not exist",
    "errorType": "USER",
    "dependency": "false"
  },
  {
    "errorCategory": "Plugin",
    "errorReason": "Input path /Users/pusaini/wsf/cdap/env/group_by_test_data_1/data.csv does not exist",
    "errorMessage": "Input path /Users/pusaini/wsf/cdap/env/group_by_test_data_1/data.csv does not exist",
    "errorType": "USER",
    "dependency": "false"
  }
]

image

@psainics psainics force-pushed the filePLuginErrorMang branch from 1e92b0c to 4bb60cf Compare January 20, 2025 04:12
@psainics psainics added the build Trigger unit test build label Jan 20, 2025
@Amit-CloudSufi Amit-CloudSufi force-pushed the filePLuginErrorMang branch 3 times, most recently from 3d77a35 to a7b066a Compare January 22, 2025 02:31
@psainics psainics marked this pull request as ready for review January 22, 2025 06:20
@@ -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)
Copy link
Member

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())
Copy link
Member

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)
Copy link
Member

@itsankit-google itsankit-google Jan 22, 2025

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);
Copy link
Member

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()));
Copy link
Member

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

Copy link
Contributor

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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw ProgramFailureException instead

import javax.annotation.Nullable;

/**
* Error details provided for the Snowflake
Copy link
Member

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())
Copy link
Member

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(
Copy link
Member

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();
Copy link
Member

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.

@psainics psainics force-pushed the filePLuginErrorMang branch from 875e48f to 8923a7d Compare January 23, 2025 08:13
* @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,
Copy link
Member

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,

Comment on lines 164 to 166
context.getFailureCollector().getOrThrowException();
}
return null;
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why SYSTEM?

@@ -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,
Copy link
Member

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()

@@ -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,
Copy link
Member

@itsankit-google itsankit-google Jan 23, 2025

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);
Copy link
Member

@itsankit-google itsankit-google Jan 23, 2025

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()

@itsankit-google
Copy link
Member

Please add a JIRA in the title

@itsankit-google itsankit-google changed the title Error Management for File plugin Source/Sink [PLUGIN-1848] Error Management for File plugin Source/Sink Jan 23, 2025
@psainics psainics merged commit 7f24625 into cdapio:develop Jan 24, 2025
5 checks passed
@psainics psainics deleted the filePLuginErrorMang branch January 24, 2025 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Trigger unit test build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants