json encode storage driver enclosed error (#4099)

This commit is contained in:
Milos Gajdos 2023-10-17 21:44:42 +01:00 committed by GitHub
commit 915ad2d5a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,7 @@ package driver
import (
"context"
"encoding/json"
"fmt"
"io"
"regexp"
@ -184,6 +185,16 @@ func (err Error) Error() string {
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
// for use within the storagedriver implementations.
type Errors struct {