Skip to content

golink: handle db.Load errors in serveDetail and serveDelete - #265

Open
RaphaelFakhri wants to merge 1 commit into
tailscale:mainfrom
RaphaelFakhri:rf-serve-load-error
Open

RaphaelFakhri wants to merge 1 commit into
tailscale:mainfrom
RaphaelFakhri:rf-serve-load-error

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Return a 500 response from serveDetail and serveDelete when loading the link fails.

Both handlers checked only for fs.ErrNotExist after db.Load. Any other error, such as a failed database query, left link nil, and the next access to link.Short or link.Owner panicked. serveSave already returns a 500 for this case. This change does the same in serveDetail and serveDelete.

Testing:

  • Added TestServeDetailDeleteDBError, which closes the database and requests /.detail/foo and /.delete/foo.
  • Without the change, the test panics with a nil pointer dereference. With the change, both requests return 500.
  • go vet . and go test . pass.

Fixes #257

serveDetail and serveDelete only handled fs.ErrNotExist from db.Load.
Any other error left link nil, and the following link.Short or
link.Owner access panicked instead of returning an error to the client.
Return a 500 the same way serveSave does.

Fixes tailscale#257

Signed-off-by: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

serveDetail and serveDelete panic when the database returns an error

1 participant