fix: Improve error handling for malformed records in SQLite storage
This commit is contained in:
@@ -4,5 +4,6 @@ import "errors"
|
||||
|
||||
// Errors for storages.
|
||||
var (
|
||||
ErrNotFound = errors.New("storage entry not found")
|
||||
ErrNotFound = errors.New("storage entry not found")
|
||||
ErrRecordMalformed = errors.New("record is malformed")
|
||||
)
|
||||
|
||||
@@ -2,16 +2,16 @@ package sqlite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/safing/portmaster/base/database/record"
|
||||
"github.com/safing/portmaster/base/database/storage"
|
||||
"github.com/safing/portmaster/base/database/storage/sqlite/models"
|
||||
"github.com/safing/structures/dsd"
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/dialect/sqlite/im"
|
||||
"github.com/stephenafamo/bob/expr"
|
||||
|
||||
"github.com/safing/portmaster/base/database/record"
|
||||
"github.com/safing/portmaster/base/database/storage/sqlite/models"
|
||||
"github.com/safing/structures/dsd"
|
||||
)
|
||||
|
||||
var UsePreparedStatements bool = true
|
||||
@@ -91,7 +91,7 @@ func writeWithPreparedStatement(ctx context.Context, pStmt *bob.StdPrepared, r r
|
||||
if r.IsWrapped() {
|
||||
wrapper, ok := r.(*record.Wrapper)
|
||||
if !ok {
|
||||
return errors.New("record is malformed (reports to be wrapped but is not of type *record.Wrapper)")
|
||||
return fmt.Errorf("%w: reports to be wrapped but is not of type *record.Wrapper", storage.ErrRecordMalformed)
|
||||
}
|
||||
format, ok = dsd.ValidateSerializationFormat(wrapper.Format)
|
||||
if !ok {
|
||||
|
||||
@@ -168,7 +168,7 @@ func (db *SQLite) putRecord(r record.Record, tx *bob.Tx) (record.Record, error)
|
||||
if r.IsWrapped() {
|
||||
wrapper, ok := r.(*record.Wrapper)
|
||||
if !ok {
|
||||
return nil, errors.New("record is malformed (reports to be wrapped but is not of type *record.Wrapper)")
|
||||
return nil, fmt.Errorf("%w: reports to be wrapped but is not of type *record.Wrapper", storage.ErrRecordMalformed)
|
||||
}
|
||||
format, ok = dsd.ValidateSerializationFormat(wrapper.Format)
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user