From fee6faef7078527be280bbb6eaad6766b1db8c01 Mon Sep 17 00:00:00 2001 From: Glyn Owen Hanmer <1295698+glynternet@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:53:27 -0600 Subject: [PATCH] json encode storage driver enclosed error Signed-off-by: Glyn Owen Hanmer <1295698+glynternet@users.noreply.github.com> --- registry/storage/driver/storagedriver.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/registry/storage/driver/storagedriver.go b/registry/storage/driver/storagedriver.go index b9ef6a14f..ef81a60e2 100644 --- a/registry/storage/driver/storagedriver.go +++ b/registry/storage/driver/storagedriver.go @@ -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 {