Skip to content

Commit

Permalink
remove dead code/never triggering nil check
Browse files Browse the repository at this point in the history
  • Loading branch information
ldemailly committed Nov 16, 2023
1 parent 4cb8e0d commit d0f1dee
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,21 +627,14 @@ func mapToString(s map[string]interface{}) string {
*/

func toJSON(v any) string {
e, isError := v.(error) // Remember and cast only once if this is an error type or not
if isError {
// Check for nil explicitly if v is an error
if e == nil {
return "null"
}
}
bytes, err := json.Marshal(v)
if err != nil {
return fmt.Sprintf("ERR marshaling %v: %v", v, err)
}
str := string(bytes)
// This is kinda hacky way to handle both structured and custom serialization errors, and
// struct with no public fields for which we need to call Error() to get a useful string.
if isError && str == "{}" {
if e, isError := v.(error); isError && str == "{}" {
return fmt.Sprintf("%q", e.Error())
}
return str
Expand Down

0 comments on commit d0f1dee

Please sign in to comment.