Skip to content

Commit

Permalink
Improve the documentation for Query
Browse files Browse the repository at this point in the history
I noticed that my `InnerText` call resulted in a panic because `Query` returned a nil. I updated the `Query` doc to mention that it may return a nil `html.Node` with no error, and improved the overall wording a little
  • Loading branch information
ffigiel authored Aug 20, 2021
1 parent 44cd157 commit 564855d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func QueryAll(top *html.Node, expr string) ([]*html.Node, error) {
return nodes, nil
}

// Query searches the html.Node that matches by the specified XPath expr,
// and return the first element of matched html.Node.
// Query runs the given XPath expression against the given html.Node and
// returns the first matching html.Node, or nil if no matches are found.
//
// Return an error if the expression `expr` cannot be parsed.
// Returns an error if the expression `expr` cannot be parsed.
func Query(top *html.Node, expr string) (*html.Node, error) {
exp, err := getQuery(expr)
if err != nil {
Expand Down

0 comments on commit 564855d

Please sign in to comment.