-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(store): wave B.13 — device repo (#269) #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,6 @@ import ( | |
|
|
||
| pm "github.com/manchtools/power-manage/sdk/gen/go/pm/v1" | ||
| "github.com/manchtools/power-manage/server/internal/store" | ||
| "github.com/manchtools/power-manage/server/internal/store/generated" | ||
| "github.com/manchtools/power-manage/server/internal/taskqueue" | ||
|
|
||
| "google.golang.org/protobuf/types/known/timestamppb" | ||
|
|
@@ -48,9 +47,7 @@ func (h *OSQueryHandler) DispatchOSQuery(ctx context.Context, req *connect.Reque | |
| } | ||
|
|
||
| // Verify device exists | ||
| _, err := h.store.Queries().GetDeviceByID(ctx, generated.GetDeviceByIDParams{ | ||
| ID: msg.DeviceId, | ||
| }) | ||
| _, err := h.store.Repos().Device.Get(ctx, store.GetDeviceKey{ID: msg.DeviceId}) | ||
| if err != nil { | ||
| return nil, apiErrorCtx(ctx, ErrDeviceNotFound, connect.CodeNotFound, "device not found") | ||
| } | ||
|
Comment on lines
+50
to
53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Differentiate not-found from repo/internal failures in both existence checks. Both checks currently return Suggested fix (apply in both methods)- _, err := h.store.Repos().Device.Get(ctx, store.GetDeviceKey{ID: msg.DeviceId})
- if err != nil {
- return nil, apiErrorCtx(ctx, ErrDeviceNotFound, connect.CodeNotFound, "device not found")
- }
+ _, err := h.store.Repos().Device.Get(ctx, store.GetDeviceKey{ID: msg.DeviceId})
+ if err != nil {
+ if store.IsNotFound(err) {
+ return nil, apiErrorCtx(ctx, ErrDeviceNotFound, connect.CodeNotFound, "device not found")
+ }
+ return nil, apiErrorCtx(ctx, ErrInternal, connect.CodeInternal, "failed to look up device")
+ }As per coding guidelines "Errors must use apiErrorCtx with proper Connect error codes. Never silently ignore errors." Also applies to: 209-212 🤖 Prompt for AI Agents |
||
|
|
@@ -195,9 +192,7 @@ func (h *OSQueryHandler) RefreshDeviceInventory(ctx context.Context, req *connec | |
| msg := req.Msg | ||
|
|
||
| // Verify device exists | ||
| _, err := h.store.Queries().GetDeviceByID(ctx, generated.GetDeviceByIDParams{ | ||
| ID: msg.DeviceId, | ||
| }) | ||
| _, err := h.store.Repos().Device.Get(ctx, store.GetDeviceKey{ID: msg.DeviceId}) | ||
| if err != nil { | ||
| return nil, apiErrorCtx(ctx, ErrDeviceNotFound, connect.CodeNotFound, "device not found") | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserve internal error semantics for device lookup.
This maps all repo errors to
CodeNotFound. Internal DB/repo failures should returnCodeInternal, otherwise outages are misreported as missing devices.Suggested fix
As per coding guidelines "Errors must use apiErrorCtx with proper Connect error codes. Never silently ignore errors."
📝 Committable suggestion
🤖 Prompt for AI Agents