Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slippy.NewTile should check tile if x and y are valid for given z #41

Open
ear7h opened this issue Jul 26, 2019 · 0 comments
Open

slippy.NewTile should check tile if x and y are valid for given z #41

ear7h opened this issue Jul 26, 2019 · 0 comments

Comments

@ear7h
Copy link
Contributor

ear7h commented Jul 26, 2019

geom/slippy/tile.go

Lines 15 to 21 in 2760310

func NewTile(z, x, y uint) *Tile {
return &Tile{
Z: z,
X: x,
Y: y,
}
}

The NewTile function simply fills in the fields but it should do input validation, for example the tile {Z:0, X: 99, Y:99} does not exist.

I can see two solutions, changing the function signature to func NewTile(z, x, y uint) (*Tile, error) or returning nil from the current function if the tile does not exist.

New Signature

pros:

  • more explicit error state
  • error state is a compile error
    • tile := slippy.NewTile(...); tile.Dereference is caught by the compiler
  • the returned error can be created in geom

cons:

  • breaking change

Return nil

pros:

  • non-breaking
  • error state would give a runtime error (better than going un-noticed)
    • tile := slippy.NewTile(...); tile.Dereference is a nil pointer dereference at runtime

cons:

  • error state is would give a runtime error (not as helpful as a compiler error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant