ocket8888 commented on code in PR #6593:
URL: https://github.com/apache/trafficcontrol/pull/6593#discussion_r856512982
##########
traffic_ops/traffic_ops_golang/server/detail.go:
##########
@@ -91,7 +91,11 @@ func GetDetailParamHandler(w http.ResponseWriter, r
*http.Request) {
routerPortName = interfaces[0].RouterPortName
}
v11server := tc.ServerDetailV11{}
- v11server.ServerDetail = server.ServerDetail
+ v11server.ServerDetail, err =
dbhelpers.GetServerDetailFromV4(server, inf.Tx.Tx)
+ if err != nil {
+ api.HandleErr(w, r, inf.Tx.Tx,
http.StatusBadRequest, nil, errors.New("failed to GetServerDetailFromV4:
"+err.Error()))
Review Comment:
`fmt.Errorf` returns an `error` type, not a `string`. The reason is because
when you make a new error by calling `err.Error()`, you're discarding the error
and only carrying its string representation forward.
In this playground I constructed the "same" error 5 different ways:
https://go.dev/play/p/oqjjeO4DcjA
When you run it, you can see that the identity of the underlying error is
only preserved in the first case - using `fmt.Errorf` with `%w`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]