($INBOX_DIR/description missing)
 help / color / mirror / Atom feed
From: <liezhi.yang@windriver.com>
To: <bitbake-devel@lists.openembedded.org>
Subject: [PATCH 1/1] bitbake: event: Improve error message for eventhandler
Date: Wed, 20 Dec 2023 20:40:32 -0800	[thread overview]
Message-ID: <2fd4acbc082469c6c665dc5499ea471d9223b42c.1703133461.git.liezhi.yang@windriver.com> (raw)
In-Reply-To: <cover.1703133461.git.liezhi.yang@windriver.com>

From: Robert Yang <liezhi.yang@windriver.com>

* Before the erorr message was:
ERROR: Unable to register event handler 'defaultbase_eventhandler':
  File "/path/to/poky/meta/classes-global/base.bbclass", line 4
    # SPDX-License-Identifier: MIT
           ^^^^^
SyntaxError: invalid syntax

This is hard to debug since the error line number 4 is incorrect, and nothing
is wrong with the code in line 4.

* Now the error message is:
ERROR: Unable to register event handler '/path/to/poky/meta/classes-global/base.bbclass':
  File "defaultbase_eventhandler", line 4
    an error line
       ^^^^^
SyntaxError: invalid syntax

This is much easier to debug.

The filename and code doesn't match since the file usually contains more code
than eventhandler, don't pass filename to compile() can fix the problem.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 bitbake/lib/bb/event.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py
index f8acacd80d1..2fbf1188d45 100644
--- a/bitbake/lib/bb/event.py
+++ b/bitbake/lib/bb/event.py
@@ -260,15 +260,17 @@ def register(name, handler, mask=None, filename=None, lineno=None, data=None):
             try:
                 code = bb.methodpool.compile_cache(tmp)
                 if not code:
-                    if filename is None:
-                        filename = "%s(e, d)" % name
-                    code = compile(tmp, filename, "exec", ast.PyCF_ONLY_AST)
+                    code = compile(tmp, name, "exec", ast.PyCF_ONLY_AST)
                     if lineno is not None:
                         ast.increment_lineno(code, lineno-1)
-                    code = compile(code, filename, "exec")
+                    code = compile(code, name, "exec")
                     bb.methodpool.compile_cache_add(tmp, code)
             except SyntaxError:
-                logger.error("Unable to register event handler '%s':\n%s", name,
+                if filename:
+                    err_msg= filename
+                else:
+                    err_msg = name
+                logger.error("Unable to register event handler '%s':\n%s", err_msg,
                              ''.join(traceback.format_exc(limit=0)))
                 _handlers[name] = noop
                 return
-- 
2.42.0



  reply	other threads:[~2023-12-21  4:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-21  4:40 [PATCH 0/1] bitbake: event: Improve error message for eventhandler liezhi.yang
2023-12-21  4:40 ` liezhi.yang [this message]
2023-12-21  9:56   ` [bitbake-devel] [PATCH 1/1] " Richard Purdie
2023-12-26 12:45     ` Robert Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2fd4acbc082469c6c665dc5499ea471d9223b42c.1703133461.git.liezhi.yang@windriver.com \
    --to=liezhi.yang@windriver.com \
    --cc=bitbake-devel@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).