forked from TrueCloudLab/frostfs-node
[#521] *: use stdlib errors
package
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
43e575cec2
commit
71b87155ef
171 changed files with 825 additions and 674 deletions
|
@ -2,13 +2,14 @@ package airportsdb
|
|||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/locode"
|
||||
locodedb "github.com/nspcc-dev/neofs-node/pkg/util/locode/db"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -177,7 +178,7 @@ func (db *DB) scanWords(pm pathMode, num int, wordsHandler func([]string) error)
|
|||
|
||||
return err
|
||||
} else if ln := len(words); ln != num {
|
||||
return errors.Errorf("unexpected number of words %d", ln)
|
||||
return fmt.Errorf("unexpected number of words %d", ln)
|
||||
}
|
||||
|
||||
if err := wordsHandler(words); err != nil {
|
||||
|
|
|
@ -2,11 +2,12 @@ package locodebolt
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
locodedb "github.com/nspcc-dev/neofs-node/pkg/util/locode/db"
|
||||
"github.com/pkg/errors"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
|
@ -21,12 +22,12 @@ func (db *DB) Open() error {
|
|||
|
||||
err := os.MkdirAll(path.Dir(db.path), db.mode)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not create dir for BoltDB")
|
||||
return fmt.Errorf("could not create dir for BoltDB: %w", err)
|
||||
}
|
||||
|
||||
db.bolt, err = bbolt.Open(db.path, db.mode, db.boltOpts)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not open BoltDB")
|
||||
return fmt.Errorf("could not open BoltDB: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -110,7 +111,7 @@ func (db *DB) Put(key locodedb.Key, rec locodedb.Record) error {
|
|||
|
||||
bktCountry, err := tx.CreateBucketIfNotExists(countryKey)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not create country bucket")
|
||||
return fmt.Errorf("could not create country bucket: %w", err)
|
||||
}
|
||||
|
||||
// TODO: write country name once in Country bucket
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package continentsdb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
locodedb "github.com/nspcc-dev/neofs-node/pkg/util/locode/db"
|
||||
"github.com/paulmach/orb"
|
||||
"github.com/paulmach/orb/geojson"
|
||||
"github.com/paulmach/orb/planar"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const continentProperty = "Continent"
|
||||
|
@ -55,12 +55,12 @@ func (db *DB) PointContinent(point *locodedb.Point) (*locodedb.Continent, error)
|
|||
func (db *DB) init() error {
|
||||
data, err := ioutil.ReadFile(db.path)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not read data file")
|
||||
return fmt.Errorf("could not read data file: %w", err)
|
||||
}
|
||||
|
||||
features, err := geojson.UnmarshalFeatureCollection(data)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not unmarshal GeoJSON feature collection")
|
||||
return fmt.Errorf("could not unmarshal GeoJSON feature collection: %w", err)
|
||||
}
|
||||
|
||||
db.features = features.Features
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package locodedb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
locodecolumn "github.com/nspcc-dev/neofs-node/pkg/util/locode/column"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// CountryCode represents country code for
|
||||
|
@ -14,7 +15,7 @@ type CountryCode locodecolumn.CountryCode
|
|||
func CountryCodeFromString(s string) (*CountryCode, error) {
|
||||
cc, err := locodecolumn.CountryCodeFromString(s)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not parse country code")
|
||||
return nil, fmt.Errorf("could not parse country code: %w", err)
|
||||
}
|
||||
|
||||
return CountryFromColumn(cc)
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package locodedb
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/locode"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// SourceTable is an interface of the UN/LOCODE table.
|
||||
|
@ -139,7 +141,7 @@ func FillDatabase(table SourceTable, airports AirportDB, continents ContinentsDB
|
|||
|
||||
continent, err := continents.PointContinent(geoPoint)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not calculate continent geo point")
|
||||
return fmt.Errorf("could not calculate continent geo point: %w", err)
|
||||
} else if continent.Is(ContinentUnknown) {
|
||||
return nil
|
||||
}
|
||||
|
@ -155,7 +157,7 @@ func FillDatabase(table SourceTable, airports AirportDB, continents ContinentsDB
|
|||
func LocodeRecord(db DB, sLocode string) (*Record, error) {
|
||||
lc, err := locode.FromString(sLocode)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not parse locode")
|
||||
return nil, fmt.Errorf("could not parse locode: %w", err)
|
||||
}
|
||||
|
||||
key, err := NewKey(*lc)
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package locodedb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
locodecolumn "github.com/nspcc-dev/neofs-node/pkg/util/locode/column"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// LocationCode represents location code for
|
||||
|
@ -14,7 +15,7 @@ type LocationCode locodecolumn.LocationCode
|
|||
func LocationCodeFromString(s string) (*LocationCode, error) {
|
||||
lc, err := locodecolumn.LocationCodeFromString(s)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not parse location code")
|
||||
return nil, fmt.Errorf("could not parse location code: %w", err)
|
||||
}
|
||||
|
||||
return LocationFromColumn(lc)
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package locodedb
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/locode"
|
||||
locodecolumn "github.com/nspcc-dev/neofs-node/pkg/util/locode/column"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Key represents the key in NeoFS location database.
|
||||
|
@ -17,12 +19,12 @@ type Key struct {
|
|||
func NewKey(lc locode.LOCODE) (*Key, error) {
|
||||
country, err := CountryCodeFromString(lc.CountryCode())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not parse country")
|
||||
return nil, fmt.Errorf("could not parse country: %w", err)
|
||||
}
|
||||
|
||||
location, err := LocationCodeFromString(lc.LocationCode())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not parse location")
|
||||
return nil, fmt.Errorf("could not parse location: %w", err)
|
||||
}
|
||||
|
||||
return &Key{
|
||||
|
@ -62,12 +64,12 @@ var errParseCoordinates = errors.New("invalid coordinates")
|
|||
func NewRecord(r locode.Record) (*Record, error) {
|
||||
crd, err := locodecolumn.CoordinatesFromString(r.Coordinates)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(errParseCoordinates, err.Error())
|
||||
return nil, fmt.Errorf("%w: %v", errParseCoordinates, err)
|
||||
}
|
||||
|
||||
point, err := PointFromCoordinates(crd)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not parse geo point")
|
||||
return nil, fmt.Errorf("could not parse geo point: %w", err)
|
||||
}
|
||||
|
||||
return &Record{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue