Skip to content

Commit

Permalink
encoding/mvt: remove github.com/pkg/errors as a dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmach committed Jan 17, 2021
1 parent ad31566 commit d2e2352
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
6 changes: 3 additions & 3 deletions encoding/mvt/geometry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package mvt

import (
"encoding/json"
"errors"
"fmt"
"reflect"

"github.com/paulmach/orb"
"github.com/paulmach/orb/encoding/mvt/vectortile"
"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -167,7 +167,7 @@ func (kve *keyValueEncoder) Value(v interface{}) (uint32, error) {
if !reflect.TypeOf(v).Comparable() {
data, err := json.Marshal(v)
if err != nil {
return 0, errors.Errorf("uncomparable: %T", v)
return 0, fmt.Errorf("uncomparable: %T", v)
}

v = string(data)
Expand Down Expand Up @@ -234,7 +234,7 @@ func encodeValue(v interface{}) (*vectortile.Tile_Value, error) {
case bool:
tv.BoolValue = &t
default:
return nil, errors.Errorf("unable to encode value of type %T: %v", v, v)
return nil, fmt.Errorf("unable to encode value of type %T: %v", v, v)
}

return tv, nil
Expand Down
11 changes: 5 additions & 6 deletions encoding/mvt/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/paulmach/orb/geojson"

"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
)

// MarshalGzipped will marshal the layers into Mapbox Vector Tile format
Expand All @@ -27,12 +26,12 @@ func MarshalGzipped(layers Layers) ([]byte, error) {

_, err = gzwriter.Write(data)
if err != nil {
return nil, errors.WithMessage(err, "failed to write gz data")
return nil, err
}

err = gzwriter.Close()
if err != nil {
return nil, errors.WithMessage(err, "failed to close gzwriter")
return nil, err
}

return buf.Bytes(), nil
Expand All @@ -58,12 +57,12 @@ func Marshal(layers Layers) ([]byte, error) {
for i, f := range l.Features {
t, g, err := encodeGeometry(f.Geometry)
if err != nil {
return nil, errors.WithMessage(err, fmt.Sprintf("layer %s: feature %d: error encoding geometry", l.Name, i))
return nil, fmt.Errorf("layer %s: feature %d: error encoding geometry: %v", l.Name, i, err)
}

tags, err := encodeProperties(kve, f.Properties)
if err != nil {
return nil, errors.WithMessage(err, fmt.Sprintf("layer %s: feature %d: error encoding properties", l.Name, i))
return nil, fmt.Errorf("layer %s: feature %d: error encoding properties: %v", l.Name, i, err)
}

layer.Features = append(layer.Features, &vectortile.Tile_Feature{
Expand All @@ -89,7 +88,7 @@ func encodeProperties(kve *keyValueEncoder, properties geojson.Properties) ([]ui
ki := kve.Key(k)
vi, err := kve.Value(v)
if err != nil {
return nil, errors.WithMessage(err, fmt.Sprintf("property %s", k))
return nil, fmt.Errorf("property %s: %v", k, err)
}

tags = append(tags, ki, vi)
Expand Down
13 changes: 7 additions & 6 deletions encoding/mvt/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@ package mvt
import (
"bytes"
"compress/gzip"
"errors"
"fmt"
"io/ioutil"

"github.com/paulmach/orb"
"github.com/paulmach/orb/encoding/mvt/vectortile"
"github.com/paulmach/orb/geojson"
"github.com/paulmach/protoscan"
"github.com/pkg/errors"
)

// UnmarshalGzipped takes gzipped Mapbox Vector Tile (MVT) data and unzips it
// before decoding it into a set of layers, It does not project the coordinates.
func UnmarshalGzipped(data []byte) (Layers, error) {
gzreader, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil {
return nil, errors.WithMessage(err, "failed to create gzreader")
return nil, fmt.Errorf("failed to create gzreader: %v", err)
}

decoded, err := ioutil.ReadAll(gzreader)
if err != nil {
return nil, errors.WithMessage(err, "failed to unzip")
return nil, fmt.Errorf("failed to unzip: %v", err)
}

return Unmarshal(decoded)
Expand Down Expand Up @@ -235,7 +236,7 @@ func (d *decoder) Geometry(geomType vectortile.Tile_GeomType) (orb.Geometry, err
gd := &geomDecoder{iter: d.geom, count: d.geom.Count(protoscan.WireTypeVarint)}

if gd.count < 2 {
return nil, errors.Errorf("geom is not long enough: %v", gd.count)
return nil, fmt.Errorf("geom is not long enough: %v", gd.count)
}

switch geomType {
Expand All @@ -247,7 +248,7 @@ func (d *decoder) Geometry(geomType vectortile.Tile_GeomType) (orb.Geometry, err
return gd.decodePolygon()
}

return nil, errors.Errorf("unknown geometry type: %v", geomType)
return nil, fmt.Errorf("unknown geometry type: %v", geomType)
}

// A geomDecoder holds state for geometry decoding.
Expand Down Expand Up @@ -392,7 +393,7 @@ func (gd *geomDecoder) cmdAndCount() (uint32, uint32, error) {

if cmd != closePath {
if v := gd.used + int(2*count); gd.count < v {
return 0, 0, errors.Errorf("data cut short: needed %d, have %d", v, gd.count)
return 0, 0, fmt.Errorf("data cut short: needed %d, have %d", v, gd.count)
}
}

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ go 1.13
require (
github.com/gogo/protobuf v1.3.1
github.com/paulmach/protoscan v0.2.0
github.com/pkg/errors v0.9.1
)
7 changes: 3 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/paulmach/protoscan v0.1.0 h1:4nM2d0bvdr4pfBC302n1/1QL9oXkenxujFXhLA19aAg=
github.com/paulmach/protoscan v0.1.0/go.mod h1:2c55sl1Hu6/tgRfc8Y8zADsxuSCYC2IrPh0JCqP/yrw=
github.com/paulmach/protoscan v0.2.0 h1:NBfMeawzxQG4ynAt0f3Q2rJh/t+4PJiU6QbFg/y9Zqk=
github.com/paulmach/protoscan v0.2.0/go.mod h1:2c55sl1Hu6/tgRfc8Y8zADsxuSCYC2IrPh0JCqP/yrw=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand All @@ -52,6 +49,7 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
Expand All @@ -68,6 +66,7 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

0 comments on commit d2e2352

Please sign in to comment.