Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions pkg/repository/kvs.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (r *kvsRepository) get(ctx context.Context, key string, value any) error {
bucket := tx.Bucket([]byte(r.bucketName))
data := bucket.Get([]byte(key))
if data == nil {
return fmt.Errorf("key %q not found", key)
return fosite.ErrNotFound
}
return json.Unmarshal(data, value)
})
Expand All @@ -61,22 +61,16 @@ func (r *kvsRepository) get(ctx context.Context, key string, value any) error {
func (r *kvsRepository) delete(ctx context.Context, key string) error {
return r.db.Update(func(tx *bbolt.Tx) error {
bucket := tx.Bucket([]byte(r.bucketName))
if bucket == nil {
return fmt.Errorf("bucket %q not found", r.bucketName)
}
return bucket.Delete([]byte(key))
})
}

func (r *kvsRepository) update(ctx context.Context, key string, value any) error {
return r.db.Update(func(tx *bbolt.Tx) error {
bucket := tx.Bucket([]byte(r.bucketName))
if bucket == nil {
return fmt.Errorf("bucket %q not found", r.bucketName)
}
data, err := json.Marshal(value)
if err != nil {
return fmt.Errorf("failed to marshal value: %w", err)
return fosite.ErrNotFound
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning fosite.ErrNotFound for a JSON marshaling error is incorrect. This error type should only be used when a resource is not found, not when serialization fails. The original error wrapping should be retained: return fmt.Errorf(\"failed to marshal value: %w\", err)

Copilot uses AI. Check for mistakes.
}
return bucket.Put([]byte(key), data)
})
Expand Down