Server error with slightly incorrect delete request #47
Labels
No Label
bug
feature
good-beginner-bug
needs-test
question
wontfix
No Milestone
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: electricdusk/rushlink#47
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I made a small typo with a delete request and got the following server error:
internal server error: runtime error: invalid memory address or nil pointer dereference
The request I tried to do was:
curl --request "DELETE" "https://hashru.link/Dwf_jpeg?deleteToken=a00e1f62d2c2f80f3c75ed425954e65e"
(missing dot in front of the jpeg)
Your request matches urlKeyExpr instead of urlKeyWithExtExpr. This means
Dwf_jpeg
is parsed as the paste key.There probably is no paste with this key. I haven't found where the nil pointer dereference comes from yet.
Found it. In https://gitea.hashru.nl/dsprenkels/rushlink/src/branch/master/internal/db/paste.go#L96,
nil, nil
is returned when a paste with the given key is not found. The calling code assumes that a non-nil
paste is returned iferr == nil
.(from an out-of-band discussion:) It would be fine to either add a custom
error
(e.g. similar toos.ErrFileNotExists
), or add abool
return value that is set tofalse
when a paste does not exist.