annotations: catch syntax errors in annotations
authorAndrea Righi <andrea.righi@canonical.com>
Mon, 5 Dec 2022 08:06:53 +0000 (09:06 +0100)
committerAndrea Righi <andrea.righi@canonical.com>
Mon, 30 Jan 2023 08:12:28 +0000 (09:12 +0100)
Trigger a syntax error when a policy or note rule is not properly
closed.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
kconfig/annotations.py

index 90e58a97a0063997d737ed41c50e7e2d531bb292..92167f806849aaa4510ef01419eb6c2dc439c9d1 100644 (file)
@@ -68,6 +68,7 @@ class Annotation(Config):
                 # Skip empty, non-policy and non-note lines
                 if re.match('.* policy<', line) or re.match('.* note<', line):
                     try:
+                        # Parse single policy or note rule
                         conf = line.split(' ')[0]
                         if conf in self.config:
                             entry = self.config[conf]
@@ -76,11 +77,13 @@ class Annotation(Config):
                         m = re.match(r'.*policy<(.*)>', line)
                         if m:
                             entry['policy'] |= literal_eval(m.group(1))
-                        m = re.match(r'.*note<(.*?)>', line)
-                        if m:
-                            entry['note'] = "'" + m.group(1).replace("'", '') + "'"
-                        if entry:
-                            self.config[conf] = entry
+                        else:
+                            m = re.match(r'.*note<(.*?)>', line)
+                            if m:
+                                entry['note'] = "'" + m.group(1).replace("'", '') + "'"
+                            else:
+                                raise Exception('syntax error')
+                        self.config[conf] = entry
                     except Exception as e:
                         raise Exception(str(e) + f', line = {line}')