AI found some issues, fix them - #299
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #299 +/- ##
==========================================
+ Coverage 79.93% 79.95% +0.02%
==========================================
Files 199 199
Lines 14800 14797 -3
==========================================
+ Hits 11830 11831 +1
+ Misses 2969 2965 -4
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
|
||
| if pointer.SafeDeref(req.Email) == "" { | ||
| return nil, errorutil.FailedPrecondition("email is required") | ||
| } |
There was a problem hiding this comment.
Shouldn't we still check if email is empty? Maybe move this check one line lower?
There was a problem hiding this comment.
Also, shouldn't email be a required field?
There was a problem hiding this comment.
but req.Email is overwritten in L121 with ownTenant.Email which is checked for not "" in L120
There was a problem hiding this comment.
Yes, but in case ownTenant.Email == "" it will remain empty and should be checked if we require it. If an email is not required then it's fine like this.
Description
1. Nil-pointer dereference before nil check —
pkg/request/authorize.go:43-46✅
req.Spec()is evaluated before thereq == nilguard, so the guard can never fire.A nil
reqpanics instead of returning the intendedInternalerror.Fix: move the nil check above line 43.
2. Inverted guard in admin machine List —
pkg/service/admin/machine/machine-service.go:77-85✅
The error only triggers when the user did specify a partition, with a message saying
"no partition specified". When the user specifies no partition and there are many available,
it silently lists across all partitions. It also overwrites an explicitly-requested partition
with the single available one.
Fix: the guard should be
if partition == nil.3. Dead / unreachable check —
pkg/service/api/tenant/tenant-service.go:120-126✅
The inner empty-check is dead code —
req.Emailwas just assignedownTenant.Email,which the guard already established is non-empty. Either the guard intent is wrong or
the inner check is misplaced.
Fix: clarify intent; remove the dead branch or fix the guard.
Consistency / maintenance concerns
4. Inconsistent error wrapping
✅
pkg/repository/network.go:126-132useserrorutil.Convert(err), whilepkg/service/admin/tenant/tenant-service.go:76-87useserrorutil.Internal("...%v", err)which discards the wrapped error via
%vinstead of%w. Some handlers wrap with%w,others with
%v— the%vcases lose the underlying error forerrors.Is/As.Fix: normalize error wrapping to
%wacross handlers.5. Variable shadowing in network create —
pkg/repository/network.go:112&141✅
An outer
vrf uintis declared, then a shadowingvar vrf uintis redeclared inside theswitch case (line 141). The
Vrf: vrfused at line 182 refers to the inner one, whilelines 226-232 mutate the outer one. Confusing and bug-prone.
Fix: collapse the duplicate
vrfdeclarations into one.Used AI-Tools ✨