json encode storage driver enclosed error

Signed-off-by: Glyn Owen Hanmer <1295698+glynternet@users.noreply.github.com>
This commit is contained in:
Glyn Owen Hanmer 2023-10-11 17:53:27 -06:00
parent f7b3869062
commit fee6faef70

View file

@ -2,6 +2,7 @@ package driver
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"io" "io"
"regexp" "regexp"
@ -184,6 +185,16 @@ func (err Error) Error() string {
return fmt.Sprintf("%s: %s", err.DriverName, err.Enclosed) return fmt.Sprintf("%s: %s", err.DriverName, err.Enclosed)
} }
func (err Error) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
DriverName string `json:"driver"`
Enclosed string `json:"enclosed"`
}{
DriverName: err.DriverName,
Enclosed: err.Enclosed.Error(),
})
}
// Errors provides the envelope for multiple errors // Errors provides the envelope for multiple errors
// for use within the storagedriver implementations. // for use within the storagedriver implementations.
type Errors struct { type Errors struct {