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

Contrary to documentation, loading a file from JSON performs validation #828

Closed
benarena opened this issue Jan 8, 2021 · 1 comment
Closed
Labels

Comments

@benarena
Copy link

benarena commented Jan 8, 2021

I noticed this when trying to load an ACH file from JSON using file.UnmarshalJSON.

The documentation states that the resulting file should be validated, as it may be invalid.

ach/file.go

Lines 98 to 103 in 85a464f

// FileFromJSON attempts to return a *File object assuming the input is valid JSON.
//
// Callers should always check for a nil-error before using the returned file.
//
// The File returned may not be valid and callers should confirm with Validate().
// Invalid files may be rejected by other Financial Institutions or ACH tools.

However, before returning a successful file, validation is called resulting in an error:

ach/file.go

Lines 166 to 168 in 85a464f

if err := file.Validate(); err != nil {
return file, err
}

I'd like to be able to validate my parsed file on my own after unmarshalling from JSON, and preferably without duplicating the behavior already present. My recommendation is to remove the validation, or at a minimum, update the documentation to more specifically address the behavior of the function.

@adamdecaf adamdecaf added the bug label Jan 11, 2021
@adamdecaf
Copy link
Member

I can see where removing this check helps to keep errors from unmarshaling and validation isolated. It'd need to be in a new minor release.

return file, err was meant to return the entire file even if Validation errors occurred, but it's non-trivial to detect which type of error was returned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants