From 8622469e1fdd4789cc45ed52093d0f329abca14e Mon Sep 17 00:00:00 2001
From: Jeremy Kersten <jke@odoo.com>
Date: Sun, 19 Jan 2020 16:17:18 +0000
Subject: [PATCH] [IMP] base: improve log for wrong xpath

Before create_multi, in case of invalid syntax used in an XPath, only
the problematic record was displayed. It was not ideal for long
definition but still usable.
Since the views are created using create_multi, the whole file content
is displayed in the error traceback, making it almost impossible to
locate on files with multiple records.

closes odoo/odoo#43542

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
---
 odoo/tools/template_inheritance.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/odoo/tools/template_inheritance.py b/odoo/tools/template_inheritance.py
index e025cd327124..1f563d6304b6 100644
--- a/odoo/tools/template_inheritance.py
+++ b/odoo/tools/template_inheritance.py
@@ -3,9 +3,11 @@ from lxml import etree
 from lxml.builder import E
 import copy
 import itertools
+import logging
 
 from odoo.tools.translate import _
 from odoo.tools import SKIPPED_ELEMENT_TYPES
+_logger = logging.getLogger(__name__)
 
 
 def add_text_before(node, text):
@@ -51,7 +53,13 @@ def locate_node(arch, spec):
     :return: a node in the source matching the spec
     """
     if spec.tag == 'xpath':
-        nodes = etree.ETXPath(spec.get('expr'))(arch)
+        expr = spec.get('expr')
+        try:
+            xPath = etree.ETXPath(expr)
+        except etree.XPathSyntaxError:
+            _logger.error("XPathSyntaxError while parsing xpath %r", expr)
+            raise
+        nodes = xPath(arch)
         return nodes[0] if nodes else None
     elif spec.tag == 'field':
         # Only compare the field name: a field can be only once in a given view
-- 
GitLab