diff --git a/cmd/root.go b/cmd/root.go index d6aa71f..65bc3aa 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -90,7 +90,7 @@ func NewRootCmd() *cobra.Command { } if err != nil { - fmt.Println(err) + fmt.Println("Error:", err) os.Exit(1) } }() diff --git a/internal/utils/utils.go b/internal/utils/utils.go index b5adab1..c4ebfb9 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "encoding/xml" + "errors" "fmt" "github.com/PuerkitoBio/goquery" "github.com/antchfx/xmlquery" @@ -230,6 +231,10 @@ func XPathQuery(reader io.Reader, writer io.Writer, query string, singleNode boo } } else { expr, _ := xpath.Compile(query) + if expr == nil { + return errors.New("unable to parse the XPath query") + } + val := expr.Evaluate(xmlquery.CreateXPathNavigator(doc)) switch typedVal := val.(type) {