Fix nil-pointer panics (#10, #11) #33

Merged
Claude merged 1 commits from fix/nil-pointer-panics into main 2026-02-15 16:18:42 +00:00
2 changed files with 13 additions and 3 deletions

View File

@@ -61,7 +61,7 @@ func (d *document) Refresh() error {
return fmt.Errorf("failed to reload page: %w", err) return fmt.Errorf("failed to reload page: %w", err)
} }
if resp.Status() != 200 { if resp != nil && resp.Status() != 200 {
return fmt.Errorf("invalid status code: %d", resp.Status()) return fmt.Errorf("invalid status code: %d", resp.Status())
} }

View File

@@ -104,15 +104,25 @@ func (c Config) Archive(ctx context.Context, b extractor.Browser, target string)
return nil, fmt.Errorf("failed to open url: %w", err) return nil, fmt.Errorf("failed to open url: %w", err)
} }
err = doc.SelectFirst("input[name='url']").Type(u.String()) urlInput := doc.SelectFirst("input[name='url']")
if urlInput == nil {
_ = doc.Close()
return nil, fmt.Errorf("failed to find url input element")
}
err = urlInput.Type(u.String())
if err != nil { if err != nil {
_ = doc.Close() _ = doc.Close()
return nil, fmt.Errorf("failed to type url: %w", err) return nil, fmt.Errorf("failed to type url: %w", err)
} }
err = doc.SelectFirst("form#submiturl input[type=\"submit\"]").Click() submitBtn := doc.SelectFirst("form#submiturl input[type=\"submit\"]")
if submitBtn == nil {
_ = doc.Close()
return nil, fmt.Errorf("failed to find submit button")
}
err = submitBtn.Click()
if err != nil { if err != nil {
_ = doc.Close() _ = doc.Close()
return nil, fmt.Errorf("failed to click submit: %w", err) return nil, fmt.Errorf("failed to click submit: %w", err)