ocket8888 commented on code in PR #6544:
URL: https://github.com/apache/trafficcontrol/pull/6544#discussion_r851529045
##########
traffic_ops/traffic_ops_golang/server/servers.go:
##########
@@ -409,7 +442,53 @@ func validateCommon(s *tc.CommonServerProperties, tx
*sql.Tx) []error {
if cdnID != *s.CDNID {
errs = append(errs, fmt.Errorf("CDN id '%d' for profile '%d'
does not match Server CDN '%d'", cdnID, *s.ProfileID, *s.CDNID))
}
+ return errs
+}
+
+func validateCommonV40(s *tc.CommonServerPropertiesV40, tx *sql.Tx) []error {
+
+ noSpaces := validation.NewStringRule(tovalidate.NoSpaces, "cannot
contain spaces")
+
+ errs := tovalidate.ToErrors(validation.Errors{
+ "cachegroupId": validation.Validate(s.CachegroupID,
validation.NotNil),
+ "cdnId": validation.Validate(s.CDNID,
validation.NotNil),
+ "domainName": validation.Validate(s.DomainName,
validation.Required, noSpaces),
+ "hostName": validation.Validate(s.HostName,
validation.Required, noSpaces),
+ "physLocationId": validation.Validate(s.PhysLocationID,
validation.NotNil),
+ "profileNames": validation.Validate(s.ProfileNames,
validation.NotNil),
+ "statusId": validation.Validate(s.StatusID,
validation.NotNil),
+ "typeId": validation.Validate(s.TypeID,
validation.NotNil),
+ "httpsPort": validation.Validate(s.HTTPSPort,
validation.By(tovalidate.IsValidPortNumber)),
+ "tcpPort": validation.Validate(s.TCPPort,
validation.By(tovalidate.IsValidPortNumber)),
+ })
+
+ if len(errs) > 0 {
+ return errs
+ }
+
+ if _, err := tc.ValidateTypeID(tx, s.TypeID, "server"); err != nil {
+ errs = append(errs, err)
+ }
+
+ if len(s.ProfileNames) == 0 {
+ errs = append(errs, fmt.Errorf("no profiles exists"))
+ }
+
+ var cdnID int
+ if err := tx.QueryRow("SELECT cdn from profile WHERE name=$1",
s.ProfileNames[0]).Scan(&cdnID); err != nil {
+ log.Errorf("could not execute select cdnID from profile: %s\n",
err)
+ if err == sql.ErrNoRows {
Review Comment:
Oh there are tons of places where it's not using `errors.Is`, and tons of
places where error-wrapping isn't being done etc. But shallow comparisons like
this will fail to work right if anything underlying the call that produces the
error wraps it. [The shallow comparison only checks for literal equivalence
while `errors.Is` unwraps errors to find out what the original error actually
was](https://go.dev/play/p/3SM1ufNb6p-).
--
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]