mirror of
https://github.com/restic/restic.git
synced 2025-10-27 20:09:41 +00:00
json: switch backup and restore errors from string to struct types
This keeps backwards compatibility with the previous empty structs. And maybe we'd want to put other fields into the inner struct later, rather than the outer message.
This commit is contained in:
@@ -67,7 +67,7 @@ func (b *JSONProgress) Update(total, processed Counter, errors uint, currentFile
|
||||
func (b *JSONProgress) ScannerError(item string, err error) error {
|
||||
b.error(errorUpdate{
|
||||
MessageType: "error",
|
||||
Error: err.Error(),
|
||||
Error: errorObject{err.Error()},
|
||||
During: "scan",
|
||||
Item: item,
|
||||
})
|
||||
@@ -78,7 +78,7 @@ func (b *JSONProgress) ScannerError(item string, err error) error {
|
||||
func (b *JSONProgress) Error(item string, err error) error {
|
||||
b.error(errorUpdate{
|
||||
MessageType: "error",
|
||||
Error: err.Error(),
|
||||
Error: errorObject{err.Error()},
|
||||
During: "archival",
|
||||
Item: item,
|
||||
})
|
||||
@@ -205,11 +205,15 @@ type statusUpdate struct {
|
||||
CurrentFiles []string `json:"current_files,omitempty"`
|
||||
}
|
||||
|
||||
type errorObject struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type errorUpdate struct {
|
||||
MessageType string `json:"message_type"` // "error"
|
||||
Error string `json:"error"`
|
||||
During string `json:"during"`
|
||||
Item string `json:"item"`
|
||||
MessageType string `json:"message_type"` // "error"
|
||||
Error errorObject `json:"error"`
|
||||
During string `json:"during"`
|
||||
Item string `json:"item"`
|
||||
}
|
||||
|
||||
type verboseUpdate struct {
|
||||
|
||||
@@ -17,11 +17,11 @@ func createJSONProgress() (*ui.MockTerminal, ProgressPrinter) {
|
||||
func TestJSONError(t *testing.T) {
|
||||
term, printer := createJSONProgress()
|
||||
test.Equals(t, printer.Error("/path", errors.New("error \"message\"")), nil)
|
||||
test.Equals(t, []string{"{\"message_type\":\"error\",\"error\":\"error \\\"message\\\"\",\"during\":\"archival\",\"item\":\"/path\"}\n"}, term.Errors)
|
||||
test.Equals(t, []string{"{\"message_type\":\"error\",\"error\":{\"message\":\"error \\\"message\\\"\"},\"during\":\"archival\",\"item\":\"/path\"}\n"}, term.Errors)
|
||||
}
|
||||
|
||||
func TestJSONScannerError(t *testing.T) {
|
||||
term, printer := createJSONProgress()
|
||||
test.Equals(t, printer.ScannerError("/path", errors.New("error \"message\"")), nil)
|
||||
test.Equals(t, []string{"{\"message_type\":\"error\",\"error\":\"error \\\"message\\\"\",\"during\":\"scan\",\"item\":\"/path\"}\n"}, term.Errors)
|
||||
test.Equals(t, []string{"{\"message_type\":\"error\",\"error\":{\"message\":\"error \\\"message\\\"\"},\"during\":\"scan\",\"item\":\"/path\"}\n"}, term.Errors)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user