($INBOX_DIR/description missing)
 help / color / mirror / Atom feed
From: Robert Yang <liezhi.yang@windriver.com>
To: Richard Purdie <richard.purdie@linuxfoundation.org>,
	bitbake-devel@lists.openembedded.org
Subject: Re: [bitbake-devel] [PATCH 1/1] bitbake: event: Improve error message for eventhandler
Date: Tue, 26 Dec 2023 20:45:29 +0800	[thread overview]
Message-ID: <4252fb37-5f44-406c-9131-80e72a1f42fc@windriver.com> (raw)
In-Reply-To: <634a0dfe7e95fb8c33f0557b4f6ea3eca19f65e7.camel@linuxfoundation.org>

Hi RP,

On 12/21/23 17:56, Richard Purdie wrote:
> On Wed, 2023-12-20 at 20:40 -0800, Robert Yang via lists.openembedded.org wrote:
>> 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.
>>
> 
> Sorry, but I really don't like this change. It is now giving a filename
> as an event handler and an event handler name as a file. To some, that
> is going to be even more confusing.
> 
> What really needs to happen here is that the line number needs to be
> fixed with the offset in the file. You'll see the code already does:
> 
> ast.increment_lineno(code, lineno-1)
> 
> so before printing the traceback, the code probably needs to account
> for that offset in the in the exception handling too.

After more investigations, the compile() or ast.parse() can't accept a lineno
argument as offset, and the ast.increment_lineno(code, lineno-1) can't work
since 'code' is None when there is an exception. And we can't fix 
traceback.tb_lineno since the tb_lineno is for event.py, not for 'code'
in compile(), it seems that we have to fix the error message in traceback.

And python 3.10.9 is worse than 3.8.10:

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

We can see the error code line (an error line)

* But in python3 3.10.9, we can't see the error code:
ERROR: Unable to register event handler 'defaultbase_eventhandler':
   File "/buildarea1/lyang1/poky/meta/classes-global/base.bbclass", line 4
     # SPDX-License-Identifier: MIT
            ^^^^^
SyntaxError: invalid syntax


I think that we can fix it in the following ways:
1) Don't pass file name to compile() to make it can report error code correctly 
in both python 3.8.10 and 3.10.9.

2) Fix the lineno offset and filename in traceback message.

Then the lineno and filename will be correct for both python versions:

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

I will send a V2 for it.

// Robert

> 
> Cheers,
> 
> Richard
> 


      reply	other threads:[~2023-12-26 12:45 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 ` [PATCH 1/1] " liezhi.yang
2023-12-21  9:56   ` [bitbake-devel] " Richard Purdie
2023-12-26 12:45     ` Robert Yang [this message]

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=4252fb37-5f44-406c-9131-80e72a1f42fc@windriver.com \
    --to=liezhi.yang@windriver.com \
    --cc=bitbake-devel@lists.openembedded.org \
    --cc=richard.purdie@linuxfoundation.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).