tinfoil-knight commented on code in PR #7402:
URL: https://github.com/apache/trafficcontrol/pull/7402#discussion_r1135248072


##########
traffic_ops/traffic_ops_golang/role/roles.go:
##########
@@ -394,24 +395,15 @@ func Update(w http.ResponseWriter, r *http.Request) {
                api.HandleErr(w, r, tx, http.StatusPreconditionFailed, 
api.ResourceModifiedError, nil)
                return
        }
-       rows, err := tx.Query(updateRoleQuery(), roleV4.Name, 
roleV4.Description, currentRoleName)
+       err = tx.QueryRow(updateRoleQuery(), roleV4.Name, roleV4.Description, 
currentRoleName).Scan(&roleV4.LastUpdated)
        if err != nil {
-               usrErr, sysErr, code := api.ParseDBError(err)
-               api.HandleErr(w, r, tx, code, usrErr, fmt.Errorf("updating 
role: %w", sysErr))
-               return
-       }
-       defer rows.Close()
-       if !rows.Next() {
-               api.HandleErr(w, r, tx, http.StatusNotFound, errors.New("no 
such role"), nil)
-               return
-       }
-       var lastUpdated time.Time
-       for rows.Next() {
-               if err := rows.Scan(&lastUpdated); err != nil {
-                       api.HandleErr(w, r, tx, http.StatusInternalServerError, 
nil, fmt.Errorf("scanning lastUpdated from role update: %w", err))
+               if err == sql.ErrNoRows {
+                       api.HandleErr(w, r, tx, http.StatusNotFound, 
errors.New("no such role"), nil)
                        return
                }
-               roleV4.LastUpdated = &lastUpdated
+               usrErr, sysErr, code := api.ParseDBError(err)
+               api.HandleErr(w, r, tx, code, usrErr, fmt.Errorf("updating role 
and scanning lastUpdated : %w", sysErr))

Review Comment:
   Note for Reviewer:
   Unlike `Query`, the `QueryRow` method returns no error. The chained `Scan` 
method returns errors for both the query & scan step.
   
   It is difficult to properly differentiate b/w errors that happened while 
updating & the ones that occurred while scanning. The error message prefix has 
thus been merged together.
   
   Ref: https://jmoiron.github.io/sqlx/#queryrow



-- 
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]

Reply via email to