artefactual-labs / bagit-gython

An experimental Go library that integrates Python's reliable BagIt implementation using an embedded modern Python interpreter.
https://pkg.go.dev/github.com/artefactual-labs/bagit-gython
Apache License 2.0
0 stars 0 forks source link

Problem: no easy way to differentiate validation errors from application errors #7

Closed djjuhasz closed 2 months ago

djjuhasz commented 2 months ago

The bagit-gython Validate() method returns a Go error for both validation errors (i.e. the program worked correctly but the bag is not valid) and application errors (e.g. the program failed unexpectedly) and it's difficult for the caller differentiate between the two types of errors.

Describe the solution you'd like

Return a custom validation error type for validation errors so the caller can check the error type to distinguish validation errors from application errors. See https://pkg.go.dev/github.com/go-ozzo/ozzo-validation/v4#Errors and https://pkg.go.dev/github.com/go-playground/validator/v10#ValidationErrors as examples.

Describe alternatives you've considered

Return validation errors as a separate value from the error value, e.g.

func (b *BagIt) Validate(path string) (validationErrs []string, err error) {

A downside of this solution is that it would be inconsistent with the Validate() interface of popular Go validation packages like https://github.com/go-playground/validator and https://github.com/go-ozzo/ozzo-validation that only return a single error value.