diff mbox series

[1/1] bb: Log str() instead of repr() for exceptions in build

Message ID 20240809115013.17469-2-tdah@bang-olufsen.dk
State New
Headers show
Series Logging str() instead of repr() on exceptions | expand

Commit Message

Troels Dalsgaard Hoffmeyer Aug. 9, 2024, 11:50 a.m. UTC
When getting errors during build, they would be printed using repr(), which
doesnt have a lot of context in some cases.
For example FileNotFoundError(2, "file or directory not found"), would be
printed, without the path of the file not found.
This changes the build logging to use str() instead, which according to
the spec is fore human readable strings, whereas repr() is for string
representations that can be be used as valid python.

Signed-off-by: Troels Dalsgaard Hoffmeyer <tdah@bang-olufsen.dk>
---
 lib/bb/build.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Richard Purdie Aug. 15, 2024, 2:01 p.m. UTC | #1
On Fri, 2024-08-09 at 13:50 +0200, Troels Dalsgaard Hoffmeyer via lists.openembedded.org wrote:
> When getting errors during build, they would be printed using repr(), which
> doesnt have a lot of context in some cases.
> For example FileNotFoundError(2, "file or directory not found"), would be
> printed, without the path of the file not found.
> This changes the build logging to use str() instead, which according to
> the spec is fore human readable strings, whereas repr() is for string
> representations that can be be used as valid python.
> 
> Signed-off-by: Troels Dalsgaard Hoffmeyer <tdah@bang-olufsen.dk>
> ---
>  lib/bb/build.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/bb/build.py b/lib/bb/build.py
> index ab8bce3d5..097730047 100644
> --- a/lib/bb/build.py
> +++ b/lib/bb/build.py
> @@ -743,7 +743,7 @@ def _exec_task(fn, task, d, quieterr):
>  
>          if quieterr:
>              if not handled:
> -                logger.warning(repr(exc))
> +                logger.warning(str(exc))
>              event.fire(TaskFailedSilent(task, fn, logfn, localdata), localdata)
>          else:
>              errprinted = errchk.triggered
> @@ -752,7 +752,7 @@ def _exec_task(fn, task, d, quieterr):
>              if verboseStdoutLogging or handled:
>                  errprinted = True
>              if not handled:
> -                logger.error(repr(exc))
> +                logger.error(str(exc))
>              event.fire(TaskFailed(task, fn, logfn, localdata, errprinted), localdata)
>          return 1
>  

Going by the python docs, this is the correct thing to do. I also know
we've had hard to debug problems due to str() not giving enough
information to debug exceptions though which does mean I'm a bit
conflicted about doing this, it feels like we're going around in
circles :(

Cheers,

Richard
diff mbox series

Patch

diff --git a/lib/bb/build.py b/lib/bb/build.py
index ab8bce3d5..097730047 100644
--- a/lib/bb/build.py
+++ b/lib/bb/build.py
@@ -743,7 +743,7 @@  def _exec_task(fn, task, d, quieterr):
 
         if quieterr:
             if not handled:
-                logger.warning(repr(exc))
+                logger.warning(str(exc))
             event.fire(TaskFailedSilent(task, fn, logfn, localdata), localdata)
         else:
             errprinted = errchk.triggered
@@ -752,7 +752,7 @@  def _exec_task(fn, task, d, quieterr):
             if verboseStdoutLogging or handled:
                 errprinted = True
             if not handled:
-                logger.error(repr(exc))
+                logger.error(str(exc))
             event.fire(TaskFailed(task, fn, logfn, localdata, errprinted), localdata)
         return 1