Skip to content

Commit

Permalink
also do error string and code style cleanup (revive defaults)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon committed Jan 28, 2024
1 parent 82ffb3c commit f7ff5bc
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pmtiles/bitmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func generalizeAnd(r *roaring64.Bitmap) {
id := iter.Next()
parentID := ParentID(id)
if parentID == current {
filled += 1
filled++
if filled == 4 {
temp.Add(parentID)
}
Expand Down
8 changes: 4 additions & 4 deletions pmtiles/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func ConvertPmtilesV2(logger *log.Logger, input string, output string, deduplica
buffer := make([]byte, 512000)
io.ReadFull(f, buffer)
if string(buffer[0:7]) == "PMTiles" && buffer[7] == 3 {
return fmt.Errorf("Archive is already the latest PMTiles version (3).")
return fmt.Errorf("archive is already the latest PMTiles version (3)")
}

v2JsonBytes, dir := ParseHeaderV2(bytes.NewReader(buffer))
Expand Down Expand Up @@ -306,7 +306,7 @@ func ConvertMbtiles(logger *log.Logger, input string, output string, deduplicate
}

if tileset.GetCardinality() == 0 {
return fmt.Errorf("No tiles in MBTiles archive.")
return fmt.Errorf("no tiles in MBTiles archive")
}

logger.Println("Pass 2: writing tiles")
Expand Down Expand Up @@ -465,7 +465,7 @@ func v2ToHeaderJSON(v2JsonMetadata map[string]interface{}, first4 []byte) (Heade
header.MaxLatE7 = maxLat
delete(v2JsonMetadata, "bounds")
} else {
return header, v2JsonMetadata, errors.New("Archive is missing bounds.")
return header, v2JsonMetadata, errors.New("archive is missing bounds")
}

if val, ok := v2JsonMetadata["center"]; ok {
Expand Down Expand Up @@ -611,7 +611,7 @@ func mbtilesToHeaderJSON(mbtilesMetadata []string) (HeaderV3, map[string]interfa
}

if minLon >= maxLon || minLat >= maxLat {
return header, jsonResult, fmt.Errorf("Error: zero-area bounds in mbtiles metadata.")
return header, jsonResult, fmt.Errorf("zero-area bounds in mbtiles metadata")
}
header.MinLonE7 = minLon
header.MinLatE7 = minLat
Expand Down
4 changes: 2 additions & 2 deletions pmtiles/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ func deserializeHeader(d []byte) (HeaderV3, error) {
h := HeaderV3{}
magicNumber := d[0:7]
if string(magicNumber) != "PMTiles" {
return h, fmt.Errorf("Magic number not detected. Are you sure this is a PMTiles archive?")
return h, fmt.Errorf("magic number not detected. confirm this is a PMTiles archive")
}

specVersion := d[7]
if specVersion > uint8(3) {
return h, fmt.Errorf("Archive is spec version %d, but this program only supports version 3: upgrade your pmtiles program.", specVersion)
return h, fmt.Errorf("archive is spec version %d, but this program only supports version 3: upgrade your pmtiles program", specVersion)
}

h.SpecVersion = specVersion
Expand Down
10 changes: 5 additions & 5 deletions pmtiles/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func RelevantEntries(bitmap *roaring64.Bitmap, maxzoom uint8, dir []EntryV3) ([]
currentRunLength = 1
currentID = y
} else {
currentRunLength += 1
currentRunLength++
}
} else {
if currentRunLength > 0 {
Expand Down Expand Up @@ -285,7 +285,7 @@ func Extract(logger *log.Logger, bucketURL string, key string, minzoom int8, max
header, err := deserializeHeader(b[0:HeaderV3LenBytes])

if !header.Clustered {
return fmt.Errorf("Error: source archive must be clustered for extracts.")
return fmt.Errorf("source archive must be clustered for extracts")
}

sourceMetadataOffset := header.MetadataOffset
Expand All @@ -300,13 +300,13 @@ func Extract(logger *log.Logger, bucketURL string, key string, minzoom int8, max
}

if minzoom > maxzoom {
return fmt.Errorf("Error: minzoom cannot be greater than maxzoom.")
return fmt.Errorf("minzoom cannot be greater than maxzoom")
}

var relevantSet *roaring64.Bitmap
if regionFile != "" || bbox != "" {
if regionFile != "" && bbox != "" {
return fmt.Errorf("Only one of region and bbox can be specified.")
return fmt.Errorf("only one of region and bbox can be specified")
}

var multipolygon orb.MultiPolygon
Expand Down Expand Up @@ -557,7 +557,7 @@ func Extract(logger *log.Logger, bucketURL string, key string, minzoom int8, max
fmt.Printf("Completed in %v with %v download threads (%v tiles/s).\n", time.Since(start), downloadThreads, float64(len(reencoded))/float64(time.Since(start).Seconds()))
totalRequests := 2 // header + root
totalRequests += numOverfetchLeaves // leaves
totalRequests += 1 // metadata
totalRequests++ // metadata
totalRequests += numOverfetchRanges
fmt.Printf("Extract required %d total requests.\n", totalRequests)
fmt.Printf("Extract transferred %s (overfetch %v) for an archive size of %s\n", humanize.Bytes(totalBytes), overfetch, humanize.Bytes(totalActualBytes))
Expand Down
14 changes: 7 additions & 7 deletions pmtiles/makesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Makesync(logger *log.Logger, cliVersion string, file string, blockSizeKb in
header, err := deserializeHeader(b[0:HeaderV3LenBytes])

if !header.Clustered {
return fmt.Errorf("Error: archive must be clustered for makesync.")
return fmt.Errorf("archive must be clustered for makesync")
}

var CollectEntries func(uint64, uint64, func(EntryV3))
Expand Down Expand Up @@ -183,9 +183,9 @@ func Makesync(logger *log.Logger, cliVersion string, file string, blockSizeKb in
} else {
if current.Length+uint64(e.Length) > blockSizeBytes {
tasks <- Block{current.Index, current.Start, current.Offset, current.Length}
blocks += 1
blocks++

currentIndex += 1
currentIndex++
current.Index = currentIndex
current.Start = e.TileID
current.Offset = e.Offset
Expand All @@ -197,7 +197,7 @@ func Makesync(logger *log.Logger, cliVersion string, file string, blockSizeKb in
})

tasks <- Block{current.Index, current.Start, current.Offset, current.Length}
blocks += 1
blocks++
close(tasks)

wg.Wait()
Expand Down Expand Up @@ -226,7 +226,7 @@ func Sync(logger *log.Logger, file string, syncfile string) error {

sync, err := os.Open(syncfile)
if err != nil {
return fmt.Errorf("Error opening syncfile: %v\n", err)
return fmt.Errorf("error opening syncfile: %v", err)
}
defer sync.Close()
scanner := bufio.NewScanner(sync)
Expand Down Expand Up @@ -276,7 +276,7 @@ func Sync(logger *log.Logger, file string, syncfile string) error {
header, err := deserializeHeader(b[0:HeaderV3LenBytes])

if !header.Clustered {
return fmt.Errorf("Error: archive must be clustered for makesync.")
return fmt.Errorf("archive must be clustered for makesync")
}

GetHash := func(offset uint64, length uint64) uint64 {
Expand Down Expand Up @@ -331,7 +331,7 @@ func Sync(logger *log.Logger, file string, syncfile string) error {
if ok {
hashResult := GetHash(e.Offset, potentialMatch.Length)
if hashResult == potentialMatch.Hash {
hits += 1
hits++
delete(byStartID, e.TileID)
}
}
Expand Down
6 changes: 3 additions & 3 deletions pmtiles/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Show(logger *log.Logger, bucketURL string, key string, showMetadataOnly boo
// check to see if it's a V2 file
if string(b[0:2]) == "PM" {
specVersion := b[2]
return fmt.Errorf("PMTiles version %d detected; please use 'pmtiles convert' to upgrade to version 3.", specVersion)
return fmt.Errorf("PMTiles version %d detected; please use 'pmtiles convert' to upgrade to version 3", specVersion)
}

return fmt.Errorf("Failed to read %s, %w", key, err)
Expand Down Expand Up @@ -89,7 +89,7 @@ func Show(logger *log.Logger, bucketURL string, key string, showMetadataOnly boo
metadataReader.Close()

if showMetadataOnly && showTilejson {
return fmt.Errorf("Cannot use --metadata and --tilejson together.")
return fmt.Errorf("cannot use --metadata and --tilejson together")
}

if showMetadataOnly {
Expand All @@ -98,7 +98,7 @@ func Show(logger *log.Logger, bucketURL string, key string, showMetadataOnly boo
if publicURL == "" {
// Using Fprintf instead of logger here, as this message should be written to Stderr in case
// Stdout is being redirected.
fmt.Fprintln(os.Stderr, "Warning: No --public-url specified; using placeholder tiles URL.")
fmt.Fprintln(os.Stderr, "no --public-url specified; using placeholder tiles URL")
}
tilejsonBytes, err := CreateTilejson(header, metadataBytes, publicURL)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pmtiles/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func Verify(logger *log.Logger, file string) error {
CollectEntries(header.RootOffset, header.RootLength, func(e EntryV3) {
offsets.Add(e.Offset)
addressedTiles += int(e.RunLength)
tileEntries += 1
tileEntries++

if e.TileID < minTileID {
minTileID = e.TileID
Expand Down

0 comments on commit f7ff5bc

Please sign in to comment.