Skip to content

Commit

Permalink
Fix godoc formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
morningvera committed Jan 12, 2020
1 parent b492aa4 commit 45661e8
Showing 1 changed file with 78 additions and 68 deletions.
146 changes: 78 additions & 68 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ func Unpack(err error) UnpackedError {
// ToCustomString returns a custom formatted string for a given eris error.
//
// To declare custom format, the Format object has to be passed as an argument.
// An error without trace will be formatted as following.
// <Root error msg>[Format.ErrorSep]<Wrap error msg>
// An error without trace will be formatted as following:
//
// An error with trace will be formatted as following.
// <Root error msg>[Format.ErrorSep]<Wrap error msg>
//
// <Root error msg>[Format.MsgStackSep]
// [Format.PreStackSep]<Method1>[Format.StackElemSep]<File1>[Format.StackElemSep]<Line1>[Format.ErrorSep]
// [Format.PreStackSep]<Method2>[Format.StackElemSep]<File2>[Format.StackElemSep]<Line2>[Format.ErrorSep]
// <Wrap error msg>[Format.MsgStackSep]
// [Format.PreStackSep]<Method2>[Format.StackElemSep]<File2>[Format.StackElemSep]<Line2>[Format.ErrorSep]
// An error with trace will be formatted as following:
//
// <Root error msg>[Format.MsgStackSep]
// [Format.PreStackSep]<Method1>[Format.StackElemSep]<File1>[Format.StackElemSep]<Line1>[Format.ErrorSep]
// [Format.PreStackSep]<Method2>[Format.StackElemSep]<File2>[Format.StackElemSep]<Line2>[Format.ErrorSep]
// <Wrap error msg>[Format.MsgStackSep]
// [Format.PreStackSep]<Method2>[Format.StackElemSep]<File2>[Format.StackElemSep]<Line2>[Format.ErrorSep]
func ToCustomString(err error, format Format) string {
upErr := Unpack(err)
if !format.WithTrace {
Expand Down Expand Up @@ -97,49 +98,54 @@ func ToCustomString(err error, format Format) string {

// ToString returns a default formatted string for a given eris error.
//
// An error without trace will be formatted as following.
// <Root error msg>: <Wrap error msg>
// An error without trace will be formatted as following:
//
// <Root error msg>: <Wrap error msg>
//
// An error with trace will be formatted as following.
// An error with trace will be formatted as following:
//
// <Root error msg>
// <Method1>:<File1>:<Line1>
// <Method2>:<File2>:<Line2>
// <Wrap error msg>
// <Method2>:<File2>:<Line2>
// <Root error msg>
// <Method1>:<File1>:<Line1>
// <Method2>:<File2>:<Line2>
// <Wrap error msg>
// <Method2>:<File2>:<Line2>
func ToString(err error, withTrace bool) string {
return ToCustomString(err, NewDefaultFormat(withTrace))
}

// ToCustomJSON returns a JSON formatted map for a given eris error.
//
// To declare custom format, the Format object has to be passed as an argument.
// An error without trace will be formatted as following.
// {
// "root": {
// "message": "Root error msg",
// },
// "wrap": [
// {
// "message": "Wrap error msg'",
// }
// ]
// }
// An error with trace will be formatted as following.
// {
// "root": {
// "message": "Root error msg",
// "stack": [ "<Method1>[Format.StackElemSep]<File1>[Format.StackElemSep]<Line1>",
// "<Method2>[Format.StackElemSep]<File2>[Format.StackElemSep]<Line2>"
// ],
// }
// "wrap": [
// {
// "message": "Wrap error msg",
// "stack": "<Method2>[Format.StackElemSep]<File2>[Format.StackElemSep]<Line2>"
// }
// ]
// }
// An error without trace will be formatted as following:
//
// {
// "root": {
// "message": "Root error msg",
// },
// "wrap": [
// {
// "message": "Wrap error msg'",
// }
// ]
// }
//
// An error with trace will be formatted as following:
//
// {
// "root": {
// "message": "Root error msg",
// "stack": [
// "<Method1>[Format.StackElemSep]<File1>[Format.StackElemSep]<Line1>",
// "<Method2>[Format.StackElemSep]<File2>[Format.StackElemSep]<Line2>"
// ]
// }
// "wrap": [
// {
// "message": "Wrap error msg",
// "stack": "<Method2>[Format.StackElemSep]<File2>[Format.StackElemSep]<Line2>"
// }
// ]
// }
func ToCustomJSON(err error, format Format) map[string]interface{} {
upErr := Unpack(err)
if !format.WithTrace {
Expand Down Expand Up @@ -168,32 +174,36 @@ func ToCustomJSON(err error, format Format) map[string]interface{} {

// ToJSON returns a JSON formatted map for a given eris error.
//
// An error without trace will be formatted as following.
// {
// "root": [
// {
// "message": "Wrap error msg"
// }
// ],
// "wrap": {
// "message": "Root error msg"
// }
// }
// An error with trace will be formatted as following.
// {
// "root": [
// {
// "message": "Wrap error msg",
// "stack": [ "<Method1>:<File1>:<Line1>",
// "<Method2>:<File2>:<Line2>"
// ]
// }
// ],
// "wrap": {
// "message": "Root error msg",
// "stack": "<Method2>:<File2>:<Line2>"
// }
// }
// An error without trace will be formatted as following:
//
// {
// "root": [
// {
// "message": "Wrap error msg"
// }
// ],
// "wrap": {
// "message": "Root error msg"
// }
// }
//
// An error with trace will be formatted as following:
//
// {
// "root": [
// {
// "message": "Wrap error msg",
// "stack": [
// "<Method1>:<File1>:<Line1>",
// "<Method2>:<File2>:<Line2>"
// ]
// }
// ],
// "wrap": {
// "message": "Root error msg",
// "stack": "<Method2>:<File2>:<Line2>"
// }
// }
func ToJSON(err error, withTrace bool) map[string]interface{} {
return ToCustomJSON(err, NewDefaultFormat(withTrace))
}
Expand Down

0 comments on commit 45661e8

Please sign in to comment.