Merge pull request #1002 from harshavardhana/content
Add JSON() printing for error and fatal messages
This commit is contained in:
@@ -17,6 +17,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
|
||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
)
|
||||
@@ -26,6 +29,18 @@ func fatalIf(err *probe.Error) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
if globalJSONFlag {
|
||||
errorMessage := ErrorMessage{
|
||||
Type: "Fatal",
|
||||
TypedError: reflect.TypeOf(err.ToError()).String(),
|
||||
EmbeddedError: err.ToError(),
|
||||
}
|
||||
if globalDebugFlag {
|
||||
errorMessage.ProbeError = err.JSON()
|
||||
}
|
||||
console.Println(errorMessage)
|
||||
os.Exit(1)
|
||||
}
|
||||
if !globalDebugFlag {
|
||||
console.Fatalln(err.ToError())
|
||||
}
|
||||
@@ -37,6 +52,18 @@ func errorIf(err *probe.Error) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
if globalJSONFlag {
|
||||
errorMessage := ErrorMessage{
|
||||
Type: "Error",
|
||||
TypedError: reflect.TypeOf(err.ToError()).String(),
|
||||
EmbeddedError: err.ToError(),
|
||||
}
|
||||
if globalDebugFlag {
|
||||
errorMessage.ProbeError = err.JSON()
|
||||
}
|
||||
console.Println(errorMessage)
|
||||
return
|
||||
}
|
||||
if !globalDebugFlag {
|
||||
console.Errorln(err.ToError())
|
||||
return
|
||||
|
||||
@@ -35,8 +35,8 @@ const (
|
||||
)
|
||||
|
||||
// parseContent parse client Content container into printer struct
|
||||
func parseContent(c *client.Content) Content {
|
||||
content := Content{}
|
||||
func parseContent(c *client.Content) ContentMessage {
|
||||
content := ContentMessage{}
|
||||
content.Time = c.Time.Local().Format(printDate)
|
||||
|
||||
// guess file type
|
||||
|
||||
+22
-3
@@ -27,6 +27,25 @@ import (
|
||||
"github.com/minio/mc/pkg/console"
|
||||
)
|
||||
|
||||
// ErrorMessage json container for error messages
|
||||
type ErrorMessage struct {
|
||||
Type string `json:"type"`
|
||||
TypedError string `json:"typed-error"`
|
||||
EmbeddedError error `json:"embedded-error"`
|
||||
ProbeError string `json:"probe-error"`
|
||||
}
|
||||
|
||||
func (e ErrorMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
return e.EmbeddedError.Error()
|
||||
}
|
||||
errorMessageBytes, err := json.MarshalIndent(e, "", "\t")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return console.JSON(string(errorMessageBytes) + "\n")
|
||||
}
|
||||
|
||||
// DiffJSONMessage json container for diff messages
|
||||
type DiffJSONMessage struct {
|
||||
FirstURL string `json:"first"`
|
||||
@@ -87,8 +106,8 @@ func (s sessionV2) String() string {
|
||||
return console.JSON(string(sessionJSONBytes) + "\n")
|
||||
}
|
||||
|
||||
// Content container for content message structure
|
||||
type Content struct {
|
||||
// ContentMessage container for content message structure
|
||||
type ContentMessage struct {
|
||||
Filetype string `json:"type"`
|
||||
Time string `json:"last-modified"`
|
||||
Size string `json:"size"`
|
||||
@@ -96,7 +115,7 @@ type Content struct {
|
||||
}
|
||||
|
||||
// String string printer for Content metadata
|
||||
func (c Content) String() string {
|
||||
func (c ContentMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
message := console.Time("[%s] ", c.Time)
|
||||
message = message + console.Size("%6s ", c.Size)
|
||||
|
||||
Reference in New Issue
Block a user