Commit 8eb0988e authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb/fs1: Factor out making zodb.OpError into FileStorage.zerr

It is already 3 places where we return zodb.OpError and it will be more.
Make a helper function to create those errors with higher signal/noise.
parent 4d2c8b1d
...@@ -98,6 +98,11 @@ type FileStorage struct { ...@@ -98,6 +98,11 @@ type FileStorage struct {
// IStorageDriver // IStorageDriver
var _ zodb.IStorageDriver = (*FileStorage)(nil) var _ zodb.IStorageDriver = (*FileStorage)(nil)
// zerr turns err into zodb.OpError about fs.op(args)
func (fs *FileStorage) zerr(op string, args interface{}, err error) *zodb.OpError {
return &zodb.OpError{URL: fs.URL(), Op: op, Args: args, Err: err}
}
func (fs *FileStorage) LastTid(_ context.Context) (zodb.Tid, error) { func (fs *FileStorage) LastTid(_ context.Context) (zodb.Tid, error) {
// XXX must be under lock // XXX must be under lock
return fs.txnhMax.Tid, nil // txnhMax.Tid = 0, if empty return fs.txnhMax.Tid, nil // txnhMax.Tid = 0, if empty
...@@ -135,7 +140,7 @@ func (fs *FileStorage) Load(_ context.Context, xid zodb.Xid) (buf *mem.Buf, seri ...@@ -135,7 +140,7 @@ func (fs *FileStorage) Load(_ context.Context, xid zodb.Xid) (buf *mem.Buf, seri
buf, serial, err = fs.load(xid) buf, serial, err = fs.load(xid)
if err != nil { if err != nil {
err = &zodb.OpError{URL: fs.URL(), Op: "load", Args: xid, Err: err} err = fs.zerr("load", xid, err)
} }
return buf, serial, err return buf, serial, err
} }
...@@ -223,7 +228,7 @@ const ( ...@@ -223,7 +228,7 @@ const (
// NextTxn iterates to next/previous transaction record according to iteration direction. // NextTxn iterates to next/previous transaction record according to iteration direction.
func (zi *zIter) NextTxn(_ context.Context) (*zodb.TxnInfo, zodb.IDataIterator, error) { func (zi *zIter) NextTxn(_ context.Context) (*zodb.TxnInfo, zodb.IDataIterator, error) {
// TODO err -> OpError("iter", tidmin..tidmax) // TODO err -> zerr("iter", tidmin..tidmax)
switch { switch {
case zi.zFlags & zIterEOF != 0: case zi.zFlags & zIterEOF != 0:
return nil, nil, io.EOF return nil, nil, io.EOF
...@@ -251,7 +256,7 @@ func (zi *zIter) NextTxn(_ context.Context) (*zodb.TxnInfo, zodb.IDataIterator, ...@@ -251,7 +256,7 @@ func (zi *zIter) NextTxn(_ context.Context) (*zodb.TxnInfo, zodb.IDataIterator,
// NextData iterates to next data record and loads data content. // NextData iterates to next data record and loads data content.
func (zi *zIter) NextData(_ context.Context) (*zodb.DataInfo, error) { func (zi *zIter) NextData(_ context.Context) (*zodb.DataInfo, error) {
// TODO err -> OpError("iter", tidmin..tidmax) // TODO err -> zerr("iter", tidmin..tidmax)
err := zi.iter.NextData() err := zi.iter.NextData()
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -388,14 +393,9 @@ func (fs *FileStorage) Iterate(_ context.Context, tidMin, tidMax zodb.Tid) zodb. ...@@ -388,14 +393,9 @@ func (fs *FileStorage) Iterate(_ context.Context, tidMin, tidMax zodb.Tid) zodb.
return ziter return ziter
case err != nil: case err != nil:
return &iterStartError{&zodb.OpError{ // XXX (?) add TidRange type which prints as
URL: fs.URL(), // "tidmin..tidmax" with omitting ends if it is either 0 or ∞
Op: "iter", return &iterStartError{fs.zerr("iter", []zodb.Tid{tidMin, tidMax}, err)}
// XXX (?) add TidRange type which prints as
// "tidmin..tidmax" with omitting ends if it is either 0 or ∞
Args: []zodb.Tid{tidMin, tidMax},
Err: err,
}}
} }
// setup iter from what findTxnRecord found // setup iter from what findTxnRecord found
...@@ -515,7 +515,7 @@ func (fs *FileStorage) Close() error { ...@@ -515,7 +515,7 @@ func (fs *FileStorage) Close() error {
close(fs.watchq) close(fs.watchq)
} }
if err != nil { if err != nil {
return &zodb.OpError{URL: fs.URL(), Op: "close", Args: nil, Err: err} return fs.zerr("close", nil, err)
} }
// TODO if opened !ro -> .saveIndex() // TODO if opened !ro -> .saveIndex()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment