From d0415e5e50384429bda6a9b6a318d6e810e0a502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Ant=C3=B3n?= Date: Tue, 12 Dec 2017 10:34:39 +0100 Subject: [PATCH 1/2] Deleted panic when compiling a xpath. Now is returned as a error --- path.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/path.go b/path.go index db38ed5..ec378e0 100644 --- a/path.go +++ b/path.go @@ -422,12 +422,12 @@ func (step *pathStep) match(node *Node) bool { // MustCompile returns the compiled path, and panics if // there are any errors. -func MustCompile(path string) *Path { +func MustCompile(path string) (*Path, error) { e, err := Compile(path) if err != nil { - panic(err) + return nil, err } - return e + return e, nil } // Compile returns the compiled path. From 3cad5cee0150fa8ac28113809f221eff6c204b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Ant=C3=B3n?= Date: Tue, 12 Dec 2017 10:35:32 +0100 Subject: [PATCH 2/2] Updated tests with the new error returned --- all_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/all_test.go b/all_test.go index dd8ae18..12a9830 100644 --- a/all_test.go +++ b/all_test.go @@ -23,7 +23,7 @@ var trivialXml = []byte(`abcdefg`) func (s *BasicSuite) TestRootText(c *C) { node, err := xmlpath.Parse(bytes.NewBuffer(trivialXml)) c.Assert(err, IsNil) - path := xmlpath.MustCompile("/") + path, _ := xmlpath.MustCompile("/") result, ok := path.String(node) c.Assert(ok, Equals, true) c.Assert(result, Equals, "abcdefg")