diff mbox series

[Unstable/Lunar,4/5] UBUNTU: [Packaging] annotations: Fail on invalid lines

Message ID 20230207073607.913994-5-juerg.haefliger@canonical.com
State New
Headers show
Series annotations: Cleanups and splitting | expand

Commit Message

Juerg Haefliger Feb. 7, 2023, 7:36 a.m. UTC
Currently, invalid lines are silently ignored, which is not good.
Fix this by raising an exception if the line can't be parsed. While at
it, remove one level of nesting by using if-continue.

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
---
 debian/scripts/misc/kconfig/annotations.py | 59 ++++++++++++----------
 1 file changed, 32 insertions(+), 27 deletions(-)
diff mbox series

Patch

diff --git a/debian/scripts/misc/kconfig/annotations.py b/debian/scripts/misc/kconfig/annotations.py
index 766405c48ec1..03b01baad46b 100644
--- a/debian/scripts/misc/kconfig/annotations.py
+++ b/debian/scripts/misc/kconfig/annotations.py
@@ -68,33 +68,38 @@  class Annotation(Config):
                 include_fname = dirname(abspath(self.fname)) + '/' + m.group(1)
                 include_data = self._load(include_fname)
                 self._parse_body(include_data)
-            else:
-                # Handle policy and note lines
-                if re.match(r'.* (policy|note)<', line):
-                    try:
-                        conf = line.split(' ')[0]
-                        if conf in self.config:
-                            entry = self.config[conf]
-                        else:
-                            entry = {'policy': {}}
-
-                        match = False
-                        m = re.match(r'.* policy<(.*?)>', line)
-                        if m:
-                            match = True
-                            entry['policy'] |= literal_eval(m.group(1))
-
-                        m = re.match(r'.* note<(.*?)>', line)
-                        if m:
-                            entry['oneline'] = match
-                            match = True
-                            entry['note'] = "'" + m.group(1).replace("'", '') + "'"
-
-                        if not match:
-                            raise Exception('syntax error')
-                        self.config[conf] = entry
-                    except Exception as e:
-                        raise Exception(str(e) + f', line = {line}')
+                continue
+
+            # Handle policy and note lines
+            if re.match(r'.* (policy|note)<', line):
+                try:
+                    conf = line.split(' ')[0]
+                    if conf in self.config:
+                        entry = self.config[conf]
+                    else:
+                        entry = {'policy': {}}
+
+                    match = False
+                    m = re.match(r'.* policy<(.*?)>', line)
+                    if m:
+                        match = True
+                        entry['policy'] |= literal_eval(m.group(1))
+
+                    m = re.match(r'.* note<(.*?)>', line)
+                    if m:
+                        entry['oneline'] = match
+                        match = True
+                        entry['note'] = "'" + m.group(1).replace("'", '') + "'"
+
+                    if not match:
+                        raise Exception('syntax error')
+                    self.config[conf] = entry
+                except Exception as e:
+                    raise Exception(str(e) + f', line = {line}')
+                continue
+
+            # Invalid line
+            raise Exception(f'invalid line: {line}')
 
     """
     Parse main annotations file, individual config options can be accessed via