bug: archive.Archive() can nil-pointer panic on SelectFirst #10

Closed
opened 2026-02-14 16:06:05 +00:00 by Claude · 2 comments
Collaborator

Parent: #1

Description

In sites/archive/archive.go:107-114:

err = doc.SelectFirst("input[name='url']").Type(u.String())

SelectFirst returns nil if the selector doesn't match any element (see nodes.go:15-19First() returns nil for empty Nodes). If the archive.ph page layout changes or loads differently, calling .Type() on a nil Node will cause a nil pointer panic.

Same issue on line 114:

err = doc.SelectFirst("form#submiturl input[type=\"submit\"]").Click()

Fix

Check for nil before calling methods:

input := doc.SelectFirst("input[name='url']")
if input == nil {
    _ = doc.Close()
    return nil, fmt.Errorf("failed to find URL input field")
}
err = input.Type(u.String())
**Parent:** #1 ## Description In `sites/archive/archive.go:107-114`: ```go err = doc.SelectFirst("input[name='url']").Type(u.String()) ``` `SelectFirst` returns `nil` if the selector doesn't match any element (see `nodes.go:15-19` — `First()` returns `nil` for empty `Nodes`). If the archive.ph page layout changes or loads differently, calling `.Type()` on a nil `Node` will cause a nil pointer panic. Same issue on line 114: ```go err = doc.SelectFirst("form#submiturl input[type=\"submit\"]").Click() ``` ## Fix Check for nil before calling methods: ```go input := doc.SelectFirst("input[name='url']") if input == nil { _ = doc.Close() return nil, fmt.Errorf("failed to find URL input field") } err = input.Type(u.String()) ```
Claude added the bugpriority/hightype/task labels 2026-02-14 16:06:17 +00:00
Author
Collaborator

Starting work on this as part of PR 2 (also includes #11). Will add nil guards for SelectFirst() results in archive.go and nil check for resp in document.go:Refresh().

Starting work on this as part of PR 2 (also includes #11). Will add nil guards for `SelectFirst()` results in `archive.go` and nil check for `resp` in `document.go:Refresh()`.
Author
Collaborator

Work finished. PR: #33

Added nil guards for SelectFirst() results in archive.go before calling .Type() and .Click().

Work finished. PR: #33 Added nil guards for `SelectFirst()` results in `archive.go` before calling `.Type()` and `.Click()`.
Sign in to join this conversation.