bitbake-devel.lists.openembedded.org archive mirror
 help / color / mirror / Atom feed
* [2.0][PATCH 1/4] utils: Allow to_boolean to support int values
@ 2023-03-10 20:45 Martin Jansa
  2023-03-10 20:45 ` [2.0][PATCH 2/4] cookerdata: Remove incorrect SystemExit usage Martin Jansa
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Martin Jansa @ 2023-03-10 20:45 UTC (permalink / raw)
  To: bitbake-devel; +Cc: steve, Richard Purdie

From: Richard Purdie <richard.purdie@linuxfoundation.org>

Some variables may be set as:

X = 1

as well the more usual

X = "1"

so add support to to_boolean to handle this case.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/utils.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index bca4830f2..cdb3c6864 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -990,6 +990,9 @@ def to_boolean(string, default=None):
     if not string:
         return default
 
+    if isinstance(string, int):
+        return string != 0
+
     normalized = string.lower()
     if normalized in ("y", "yes", "1", "true"):
         return True
-- 
2.39.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [2.0][PATCH 2/4] cookerdata: Remove incorrect SystemExit usage
  2023-03-10 20:45 [2.0][PATCH 1/4] utils: Allow to_boolean to support int values Martin Jansa
@ 2023-03-10 20:45 ` Martin Jansa
  2023-03-10 20:46 ` [2.0][PATCH 3/4] cookerdata: Improve early exception handling Martin Jansa
  2023-03-10 20:46 ` [2.0][PATCH 4/4] cookerdata: Drop dubious exception handling code Martin Jansa
  2 siblings, 0 replies; 4+ messages in thread
From: Martin Jansa @ 2023-03-10 20:45 UTC (permalink / raw)
  To: bitbake-devel; +Cc: steve, Richard Purdie

From: Richard Purdie <richard.purdie@linuxfoundation.org>

Calling SystemExit doesn't work well with server/client usage since the string
isn't printed to the right place. Use bb.fatal() instead which prints the right
log output and raises and handled exception which then shows correctly on the
UI.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/cookerdata.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/bb/cookerdata.py b/lib/bb/cookerdata.py
index fe5696c70..efa671aa0 100644
--- a/lib/bb/cookerdata.py
+++ b/lib/bb/cookerdata.py
@@ -435,7 +435,7 @@ class CookerDataBuilder(object):
                 msg += (" and bitbake did not find a conf/bblayers.conf file in"
                         " the expected location.\nMaybe you accidentally"
                         " invoked bitbake from the wrong directory?")
-            raise SystemExit(msg)
+            bb.fatal(msg)
 
         if not data.getVar("TOPDIR"):
             data.setVar("TOPDIR", os.path.abspath(os.getcwd()))
-- 
2.39.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [2.0][PATCH 3/4] cookerdata: Improve early exception handling
  2023-03-10 20:45 [2.0][PATCH 1/4] utils: Allow to_boolean to support int values Martin Jansa
  2023-03-10 20:45 ` [2.0][PATCH 2/4] cookerdata: Remove incorrect SystemExit usage Martin Jansa
@ 2023-03-10 20:46 ` Martin Jansa
  2023-03-10 20:46 ` [2.0][PATCH 4/4] cookerdata: Drop dubious exception handling code Martin Jansa
  2 siblings, 0 replies; 4+ messages in thread
From: Martin Jansa @ 2023-03-10 20:46 UTC (permalink / raw)
  To: bitbake-devel; +Cc: steve, Richard Purdie

From: Richard Purdie <richard.purdie@linuxfoundation.org>

Martin Jansa reported that if you put a syntax error into an imported
module such as qa.py in OE, no error is shown.

Part of the issue appears to be that the catch_parse_error() decorator only
catches certain exceptions and SyntaxError isn't one of them. As far as I can
tell we should remove all the special cases and use the more advanced code
in all cases, not just expansion errors.

I confirmed this now prints a proper error message for a qa.py syntax error.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/cookerdata.py | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/lib/bb/cookerdata.py b/lib/bb/cookerdata.py
index efa671aa0..e2dbb3b21 100644
--- a/lib/bb/cookerdata.py
+++ b/lib/bb/cookerdata.py
@@ -160,12 +160,7 @@ def catch_parse_error(func):
     def wrapped(fn, *args):
         try:
             return func(fn, *args)
-        except IOError as exc:
-            import traceback
-            parselog.critical(traceback.format_exc())
-            parselog.critical("Unable to parse %s: %s" % (fn, exc))
-            raise bb.BBHandledException()
-        except bb.data_smart.ExpansionError as exc:
+        except Exception as exc:
             import traceback
 
             bbdir = os.path.dirname(__file__) + os.sep
@@ -177,9 +172,6 @@ def catch_parse_error(func):
                     break
             parselog.critical("Unable to parse %s" % fn, exc_info=(exc_class, exc, tb))
             raise bb.BBHandledException()
-        except bb.parse.ParseError as exc:
-            parselog.critical(str(exc))
-            raise bb.BBHandledException()
     return wrapped
 
 @catch_parse_error
-- 
2.39.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [2.0][PATCH 4/4] cookerdata: Drop dubious exception handling code
  2023-03-10 20:45 [2.0][PATCH 1/4] utils: Allow to_boolean to support int values Martin Jansa
  2023-03-10 20:45 ` [2.0][PATCH 2/4] cookerdata: Remove incorrect SystemExit usage Martin Jansa
  2023-03-10 20:46 ` [2.0][PATCH 3/4] cookerdata: Improve early exception handling Martin Jansa
@ 2023-03-10 20:46 ` Martin Jansa
  2 siblings, 0 replies; 4+ messages in thread
From: Martin Jansa @ 2023-03-10 20:46 UTC (permalink / raw)
  To: bitbake-devel; +Cc: steve, Richard Purdie

From: Richard Purdie <richard.purdie@linuxfoundation.org>

This code appears to be dangerous, it swallows exceptions, turning them into
"handled" versions which then show no errors to the user. This is a pretty
poor user experience and I can't see why this code should be swallowing
such things. Drop the worst bits of code.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/cookerdata.py | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/lib/bb/cookerdata.py b/lib/bb/cookerdata.py
index e2dbb3b21..ec3741cc1 100644
--- a/lib/bb/cookerdata.py
+++ b/lib/bb/cookerdata.py
@@ -293,14 +293,9 @@ class CookerDataBuilder(object):
                 bb.event.fire(bb.event.MultiConfigParsed(self.mcdata), self.data)
 
             self.data_hash = data_hash.hexdigest()
-        except (SyntaxError, bb.BBHandledException):
-            raise bb.BBHandledException()
         except bb.data_smart.ExpansionError as e:
             logger.error(str(e))
             raise bb.BBHandledException()
-        except Exception:
-            logger.exception("Error parsing configuration files")
-            raise bb.BBHandledException()
 
 
         # Handle obsolete variable names
-- 
2.39.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-10 20:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-10 20:45 [2.0][PATCH 1/4] utils: Allow to_boolean to support int values Martin Jansa
2023-03-10 20:45 ` [2.0][PATCH 2/4] cookerdata: Remove incorrect SystemExit usage Martin Jansa
2023-03-10 20:46 ` [2.0][PATCH 3/4] cookerdata: Improve early exception handling Martin Jansa
2023-03-10 20:46 ` [2.0][PATCH 4/4] cookerdata: Drop dubious exception handling code Martin Jansa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).