Skip to content

Commit

Permalink
fix(logging): do not panic in library code (#1862)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoleczhu committed Oct 23, 2020
1 parent 846989f commit 04b40d4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions logging/logging.go
Expand Up @@ -180,7 +180,7 @@ func init() {
var err error
unixZeroTimestamp, err = ptypes.TimestampProto(time.Unix(0, 0))
if err != nil {
panic(err)
log.Fatalf("ptypes.TimestampProto(time.Unix(0,0)) failed: %v", err)
}
}

Expand Down Expand Up @@ -700,7 +700,8 @@ func fromHTTPRequest(r *HTTPRequest) *logtypepb.HttpRequest {
return nil
}
if r.Request == nil {
panic("HTTPRequest must have a non-nil Request")
log.Println("Error: HTTPRequest must have a non-nil Request")
return nil
}
u := *r.Request.URL
u.Fragment = ""
Expand Down Expand Up @@ -803,7 +804,8 @@ func jsonValueToStructValue(v interface{}) *structpb.Value {
}
return &structpb.Value{Kind: &structpb.Value_ListValue{ListValue: &structpb.ListValue{Values: vals}}}
default:
panic(fmt.Sprintf("bad type %T for JSON value", v))
log.Printf("Error: bad type %T for JSON value", v)
return &structpb.Value{Kind: &structpb.Value_NullValue{}}
}
}

Expand Down

0 comments on commit 04b40d4

Please sign in to comment.