utils: Ensure shell function failure in python logging is correct

Message ID 20220221160356.3167661-1-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit 7cae11f558f9ff5fd05ef23b789aaef92fb5a327
Headers show
Series utils: Ensure shell function failure in python logging is correct | expand

Commit Message

Richard Purdie Feb. 21, 2022, 4:03 p.m. UTC
If a python function exec_func() calls a shell task, the logging wasn't working
correctly in all cases since the exception was turned into a BBHandledException()
and the logfile piece was lost which is handled at the top task level.

The easiest way to avoid this is to allow the ExecutionError exceptions to
be raised to a higher level, we don't need the traceback for them.

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

Comments

Peter Kjellerstedt March 8, 2022, 10:39 a.m. UTC | #1
> -----Original Message-----
> From: bitbake-devel@lists.openembedded.org <bitbake-devel@lists.openembedded.org> On Behalf Of Richard Purdie
> Sent: den 21 februari 2022 17:04
> To: bitbake-devel@lists.openembedded.org
> Subject: [bitbake-devel] [PATCH] utils: Ensure shell function failure in
> python logging is correct
> 
> If a python function exec_func() calls a shell task, the logging wasn't working
> correctly in all cases since the exception was turned into a BBHandledException()
> and the logfile piece was lost which is handled at the top task level.
> 
> The easiest way to avoid this is to allow the ExecutionError exceptions to
> be raised to a higher level, we don't need the traceback for them.
> 
> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> ---
>  lib/bb/utils.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/bb/utils.py b/lib/bb/utils.py
> index 2c22535424..2e8256101a 100644
> --- a/lib/bb/utils.py
> +++ b/lib/bb/utils.py
> @@ -402,7 +402,7 @@ def better_exec(code, context, text = None, realfile = "<code>", pythonexception
>          code = better_compile(code, realfile, realfile)
>      try:
>          exec(code, get_context(), context)
> -    except (bb.BBHandledException, bb.parse.SkipRecipe, bb.data_smart.ExpansionError):
> +    except (bb.BBHandledException, bb.parse.SkipRecipe, bb.data_smart.ExpansionError, bb.process.ExecutionError):
>          # Error already shown so passthrough, no need for traceback
>          raise
>      except Exception as e:
> --
> 2.32.0

This needs to be cherry-picked to Honister. There are corresponding 
patches for oe-selftest as well to exercise the above change, but I'm 
not sure if you normally backport them too.

//Peter

Patch

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 2c22535424..2e8256101a 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -402,7 +402,7 @@  def better_exec(code, context, text = None, realfile = "<code>", pythonexception
         code = better_compile(code, realfile, realfile)
     try:
         exec(code, get_context(), context)
-    except (bb.BBHandledException, bb.parse.SkipRecipe, bb.data_smart.ExpansionError):
+    except (bb.BBHandledException, bb.parse.SkipRecipe, bb.data_smart.ExpansionError, bb.process.ExecutionError):
         # Error already shown so passthrough, no need for traceback
         raise
     except Exception as e: