| Message ID | 20261013-warn-as-errors-v1-3-ab3658758ceb@bootlin.com |
|---|---|
| State | New |
| Headers | show |
| Series | Add -W to treat warnings as errors | expand |
On Tue, 2026-10-13 at 14:13 +0200, Antonin Godard via lists.openembedded.org wrote: > When -W is passed, modify the handlers to show warnings in red and set > the return value to 1. Add a summary line informing the user that the -W > option was used as it might not be obvious when looking at the bottom > the end of the console log. The trouble is this doesn't make warnings behave exactly as errors and I think that is going to confuse people :/. Specifically, if an error is encountered in a task, it will error and fail. The warning will show an error but continue anyway. I also suspect the warnings will still show as warnings in the log files and only appear as errors on the console. Cheers, Richard
On Thu Oct 15, 2026 at 10:58 AM CEST, Richard Purdie via lists.yoctoproject.org wrote: > On Tue, 2026-10-13 at 14:13 +0200, Antonin Godard via lists.openembedded.org wrote: >> When -W is passed, modify the handlers to show warnings in red and set >> the return value to 1. Add a summary line informing the user that the -W >> option was used as it might not be obvious when looking at the bottom >> the end of the console log. > > The trouble is this doesn't make warnings behave exactly as errors and > I think that is going to confuse people :/. > > Specifically, if an error is encountered in a task, it will error and > fail. The warning will show an error but continue anyway. I also > suspect the warnings will still show as warnings in the log files and > only appear as errors on the console. Good point. So there's two directions this could take (if we want that feature): - Make this option change the behavior of warnings, and make them _act_ (not just look) like errors, so a given task would stop in case of warning. - Rename the option and make it clearer: warnings are still warnings but the return code will be 1 if there are any. Maybe "-W,--fail-on-warnings: Make bitbake return 1 if any warning is emitted"? I feel like the second option might be best as the first one is changing the behavior of tasks and I also think this might not be desirable. With the second option it allows having a positive exit code on warnings while still being able to have a look at all of them (not only the single one that stopped the build as would happen with the first option), just as you would with a normal bitbake execution. Antonin
On Thu, 2026-10-15 at 12:25 +0200, Antonin Godard wrote: > On Thu Oct 15, 2026 at 10:58 AM CEST, Richard Purdie via lists.yoctoproject.org wrote: > > On Tue, 2026-10-13 at 14:13 +0200, Antonin Godard via lists.openembedded.org wrote: > > > When -W is passed, modify the handlers to show warnings in red and set > > > the return value to 1. Add a summary line informing the user that the -W > > > option was used as it might not be obvious when looking at the bottom > > > the end of the console log. > > > > The trouble is this doesn't make warnings behave exactly as errors and > > I think that is going to confuse people :/. > > > > Specifically, if an error is encountered in a task, it will error and > > fail. The warning will show an error but continue anyway. I also > > suspect the warnings will still show as warnings in the log files and > > only appear as errors on the console. > > Good point. So there's two directions this could take (if we want that feature): > > - Make this option change the behavior of warnings, and make them _act_ (not > just look) like errors, so a given task would stop in case of warning. > > - Rename the option and make it clearer: warnings are still warnings but the > return code will be 1 if there are any. > > Maybe "-W,--fail-on-warnings: Make bitbake return 1 if any warning is > emitted"? > > I feel like the second option might be best as the first one is changing the > behavior of tasks and I also think this might not be desirable. > > With the second option it allows having a positive exit code on warnings while > still being able to have a look at all of them (not only the single one that > stopped the build as would happen with the first option), just as you would with > a normal bitbake execution. I think we need to see if there are others wanting this feature or not. I think with new option additions like this, we need to see a clear demand from the userbase for it. That feedback may also make it clearer which behaviour people would want. Cheers, Richard
On Thu Oct 15, 2026 at 1:49 PM CEST, Richard Purdie wrote: > On Thu, 2026-10-15 at 12:25 +0200, Antonin Godard wrote: >> On Thu Oct 15, 2026 at 10:58 AM CEST, Richard Purdie via lists.yoctoproject.org wrote: >> > On Tue, 2026-10-13 at 14:13 +0200, Antonin Godard via lists.openembedded.org wrote: >> > > When -W is passed, modify the handlers to show warnings in red and set >> > > the return value to 1. Add a summary line informing the user that the -W >> > > option was used as it might not be obvious when looking at the bottom >> > > the end of the console log. >> > >> > The trouble is this doesn't make warnings behave exactly as errors and >> > I think that is going to confuse people :/. >> > >> > Specifically, if an error is encountered in a task, it will error and >> > fail. The warning will show an error but continue anyway. I also >> > suspect the warnings will still show as warnings in the log files and >> > only appear as errors on the console. >> >> Good point. So there's two directions this could take (if we want that feature): >> >> - Make this option change the behavior of warnings, and make them _act_ (not >> just look) like errors, so a given task would stop in case of warning. >> >> - Rename the option and make it clearer: warnings are still warnings but the >> return code will be 1 if there are any. >> >> Maybe "-W,--fail-on-warnings: Make bitbake return 1 if any warning is >> emitted"? >> >> I feel like the second option might be best as the first one is changing the >> behavior of tasks and I also think this might not be desirable. >> >> With the second option it allows having a positive exit code on warnings while >> still being able to have a look at all of them (not only the single one that >> stopped the build as would happen with the first option), just as you would with >> a normal bitbake execution. > > I think we need to see if there are others wanting this feature or not. > I think with new option additions like this, we need to see a clear > demand from the userbase for it. That feedback may also make it clearer > which behaviour people would want. Ross (copied here) was talking about it on IRC[1]. Hard to say which way or the other was desired from this conversation though. It did give me the idea to contribute this feature as I also need it sometimes. I personally have seen multiple projects where builds started in CI environments needed to stop when warnings are emitted. I'm happy to keep my scripts as they are but I thought this series would make things a bit easier for users. I cannot say which solution for it the userbase would prefer though! [1]: https://libera.catirclogs.org/yocto/2026-09-03#1788452760-1788454399; Antonin
On Thu, 2026-10-15 at 14:23 +0200, Antonin Godard wrote: > On Thu Oct 15, 2026 at 1:49 PM CEST, Richard Purdie wrote: > > On Thu, 2026-10-15 at 12:25 +0200, Antonin Godard wrote: > > > On Thu Oct 15, 2026 at 10:58 AM CEST, Richard Purdie via lists.yoctoproject.org wrote: > > > > On Tue, 2026-10-13 at 14:13 +0200, Antonin Godard via lists.openembedded.org wrote: > > > > > When -W is passed, modify the handlers to show warnings in red and set > > > > > the return value to 1. Add a summary line informing the user that the -W > > > > > option was used as it might not be obvious when looking at the bottom > > > > > the end of the console log. > > > > > > > > The trouble is this doesn't make warnings behave exactly as errors and > > > > I think that is going to confuse people :/. > > > > > > > > Specifically, if an error is encountered in a task, it will error and > > > > fail. The warning will show an error but continue anyway. I also > > > > suspect the warnings will still show as warnings in the log files and > > > > only appear as errors on the console. > > > > > > Good point. So there's two directions this could take (if we want that feature): > > > > > > - Make this option change the behavior of warnings, and make them _act_ (not > > > just look) like errors, so a given task would stop in case of warning. > > > > > > - Rename the option and make it clearer: warnings are still warnings but the > > > return code will be 1 if there are any. > > > > > > Maybe "-W,--fail-on-warnings: Make bitbake return 1 if any warning is > > > emitted"? > > > > > > I feel like the second option might be best as the first one is changing the > > > behavior of tasks and I also think this might not be desirable. > > > > > > With the second option it allows having a positive exit code on warnings while > > > still being able to have a look at all of them (not only the single one that > > > stopped the build as would happen with the first option), just as you would with > > > a normal bitbake execution. > > > > I think we need to see if there are others wanting this feature or not. > > I think with new option additions like this, we need to see a clear > > demand from the userbase for it. That feedback may also make it clearer > > which behaviour people would want. > > Ross (copied here) was talking about it on IRC[1]. Hard to say which way or the > other was desired from this conversation though. It did give me the idea to > contribute this feature as I also need it sometimes. > > I personally have seen multiple projects where builds started in CI environments > needed to stop when warnings are emitted. I'm happy to keep my scripts as they > are but I thought this series would make things a bit easier for users. Do you really want to "stop" on warnings though? Usually you want a list of *all* the warnings, not just the first one. You probably do want to continue through all the rest of the tasks too. That makes it sound like you want to just change the exit code, which is a bit of a different discussion... Cheers, Richard
On Thu Oct 15, 2026 at 3:04 PM CEST, Richard Purdie wrote: > On Thu, 2026-10-15 at 14:23 +0200, Antonin Godard wrote: >> On Thu Oct 15, 2026 at 1:49 PM CEST, Richard Purdie wrote: >> > On Thu, 2026-10-15 at 12:25 +0200, Antonin Godard wrote: >> > > On Thu Oct 15, 2026 at 10:58 AM CEST, Richard Purdie via lists.yoctoproject.org wrote: >> > > > On Tue, 2026-10-13 at 14:13 +0200, Antonin Godard via lists.openembedded.org wrote: >> > > > > When -W is passed, modify the handlers to show warnings in red and set >> > > > > the return value to 1. Add a summary line informing the user that the -W >> > > > > option was used as it might not be obvious when looking at the bottom >> > > > > the end of the console log. >> > > > >> > > > The trouble is this doesn't make warnings behave exactly as errors and >> > > > I think that is going to confuse people :/. >> > > > >> > > > Specifically, if an error is encountered in a task, it will error and >> > > > fail. The warning will show an error but continue anyway. I also >> > > > suspect the warnings will still show as warnings in the log files and >> > > > only appear as errors on the console. >> > > >> > > Good point. So there's two directions this could take (if we want that feature): >> > > >> > > - Make this option change the behavior of warnings, and make them _act_ (not >> > > just look) like errors, so a given task would stop in case of warning. >> > > >> > > - Rename the option and make it clearer: warnings are still warnings but the >> > > return code will be 1 if there are any. >> > > >> > > Maybe "-W,--fail-on-warnings: Make bitbake return 1 if any warning is >> > > emitted"? >> > > >> > > I feel like the second option might be best as the first one is changing the >> > > behavior of tasks and I also think this might not be desirable. >> > > >> > > With the second option it allows having a positive exit code on warnings while >> > > still being able to have a look at all of them (not only the single one that >> > > stopped the build as would happen with the first option), just as you would with >> > > a normal bitbake execution. >> > >> > I think we need to see if there are others wanting this feature or not. >> > I think with new option additions like this, we need to see a clear >> > demand from the userbase for it. That feedback may also make it clearer >> > which behaviour people would want. >> >> Ross (copied here) was talking about it on IRC[1]. Hard to say which way or the >> other was desired from this conversation though. It did give me the idea to >> contribute this feature as I also need it sometimes. >> >> I personally have seen multiple projects where builds started in CI environments >> needed to stop when warnings are emitted. I'm happy to keep my scripts as they >> are but I thought this series would make things a bit easier for users. > > Do you really want to "stop" on warnings though? Usually you want a > list of *all* the warnings, not just the first one. You probably do > want to continue through all the rest of the tasks too. No, I don't want to stop on the first warning. I wasn't clear, sorry. > That makes it sound like you want to just change the exit code, which > is a bit of a different discussion... Yes, exactly, the goal would be to return 1 if at least 1 warning is emitted, which I think is a common use-case. Antonin
Hi, two cents from my side. I think that warnings as errors would ideally work like normal -Werror in compilers. 1. Regarding name: -W doesn't indicate anything about errors. Only something with warnings. I am not sure if having this short option is worth it. 2. This might be controversial, but ability to do -Wno-error, would be great. Problem is we don't have categorized/named warnings/errors. But I think that it could support a syntax where we use file name (or partial match on its path) and disable warnings-as-errors for that source file. Or this might be even easier to implement: regex for warning message. It it matches, it won't be treated as an error. 3. Exit code only change won't force developers to immediately fix their code as it's really easy to ignore in interactive terminals. Sure, later CI would catch it, but I would prefer early fail if possible. Br, Michal
Hi, On Fri Oct 16, 2026 at 9:59 AM CEST, Michal Sieron via lists.openembedded.org wrote: > Hi, > > two cents from my side. I think that warnings as errors would ideally work like normal -Werror in compilers. > > 1. Regarding name: -W doesn't indicate anything about errors. Only something > with warnings. I am not sure if having this short option is worth it. I agree. > 2. This might be controversial, but ability to do -Wno-error, would be great. > Problem is we don't have categorized/named warnings/errors. But I think > that it could support a syntax where we use file name (or partial match on > its path) and disable warnings-as-errors for that source file. Or this > might be even easier to implement: regex for warning message. It it > matches, it won't be treated as an error. That sounds like an interesting idea - but maybe as a follow-up of this though? > 3. Exit code only change won't force developers to immediately fix their code > as it's really easy to ignore in interactive terminals. Sure, later CI > would catch it, but I would prefer early fail if possible. That's true - however, I checked again, and error messages originating from bb.error (or bberror) do NOT stop the execution of bitbake. This is the role of bb.fatal (or bbfatal). bb.error only affects the return code of bitbake, but goes as far as possible - for example I was able to build an image recipe even though one of its recipes emitted a bb.error. So if we want warnings to act like errors, I think this is already what this series does. If we want warnings/errors to act like bb.fatal, that's another question. Antonin
On Fri, 2026-10-16 at 15:11 +0200, Antonin Godard via lists.openembedded.org wrote: > Hi, > > On Fri Oct 16, 2026 at 9:59 AM CEST, Michal Sieron via lists.openembedded.org wrote: > > Hi, > > > > two cents from my side. I think that warnings as errors would ideally work like normal -Werror in compilers. > > > > 1. Regarding name: -W doesn't indicate anything about errors. Only something > > with warnings. I am not sure if having this short option is worth it. > > I agree. > > > 2. This might be controversial, but ability to do -Wno-error, would be great. > > Problem is we don't have categorized/named warnings/errors. But I think > > that it could support a syntax where we use file name (or partial match on > > its path) and disable warnings-as-errors for that source file. Or this > > might be even easier to implement: regex for warning message. It it > > matches, it won't be treated as an error. > > That sounds like an interesting idea - but maybe as a follow-up of this though? > > > 3. Exit code only change won't force developers to immediately fix their code > > as it's really easy to ignore in interactive terminals. Sure, later CI > > would catch it, but I would prefer early fail if possible. > > That's true - however, I checked again, and error messages originating from > bb.error (or bberror) do NOT stop the execution of bitbake. This is the role of > bb.fatal (or bbfatal). bb.error only affects the return code of bitbake, but > goes as far as possible - for example I was able to build an image recipe even > though one of its recipes emitted a bb.error. > > So if we want warnings to act like errors, I think this is already what this > series does. If we want warnings/errors to act like bb.fatal, that's another > question. I should also mention that ERROR_QA and WARN_QA allow many warnings to actually become errors. That is the mechanism we should really be pointing people at if they want errors IMO... Cheers, Richard
On Sat Oct 17, 2026 at 5:02 PM CEST, Richard Purdie wrote: > On Fri, 2026-10-16 at 15:11 +0200, Antonin Godard via lists.openembedded.org wrote: >> Hi, >> >> On Fri Oct 16, 2026 at 9:59 AM CEST, Michal Sieron via lists.openembedded.org wrote: >> > Hi, >> > >> > two cents from my side. I think that warnings as errors would ideally work like normal -Werror in compilers. >> > >> > 1. Regarding name: -W doesn't indicate anything about errors. Only something >> > with warnings. I am not sure if having this short option is worth it. >> >> I agree. >> >> > 2. This might be controversial, but ability to do -Wno-error, would be great. >> > Problem is we don't have categorized/named warnings/errors. But I think >> > that it could support a syntax where we use file name (or partial match on >> > its path) and disable warnings-as-errors for that source file. Or this >> > might be even easier to implement: regex for warning message. It it >> > matches, it won't be treated as an error. >> >> That sounds like an interesting idea - but maybe as a follow-up of this though? >> >> > 3. Exit code only change won't force developers to immediately fix their code >> > as it's really easy to ignore in interactive terminals. Sure, later CI >> > would catch it, but I would prefer early fail if possible. >> >> That's true - however, I checked again, and error messages originating from >> bb.error (or bberror) do NOT stop the execution of bitbake. This is the role of >> bb.fatal (or bbfatal). bb.error only affects the return code of bitbake, but >> goes as far as possible - for example I was able to build an image recipe even >> though one of its recipes emitted a bb.error. >> >> So if we want warnings to act like errors, I think this is already what this >> series does. If we want warnings/errors to act like bb.fatal, that's another >> question. > > I should also mention that ERROR_QA and WARN_QA allow many warnings to > actually become errors. That is the mechanism we should really be > pointing people at if they want errors IMO... Sure, but this couldn't possibly cover all warnings? Maybe I can reword the intent of this series: give users an easy way of knowing when one or more warnings were emitted so that they look at them instead of ignoring them. Whether we should stop bitbake immediately on a warning or not seems to be another question as per my previous email. From your answers, I'm not really sure of whether you approve or deny of this idea though. Should I send a v2 with a long option only (--fail-on-warnings), and keep the rest as-is? Antonin
On Wed, 2026-10-21 at 16:42 +0200, Antonin Godard wrote: > On Sat Oct 17, 2026 at 5:02 PM CEST, Richard Purdie wrote: > > On Fri, 2026-10-16 at 15:11 +0200, Antonin Godard via lists.openembedded.org wrote: > > > Hi, > > > > > > On Fri Oct 16, 2026 at 9:59 AM CEST, Michal Sieron via lists.openembedded.org wrote: > > > > Hi, > > > > > > > > two cents from my side. I think that warnings as errors would ideally work like normal -Werror in compilers. > > > > > > > > 1. Regarding name: -W doesn't indicate anything about errors. Only something > > > > with warnings. I am not sure if having this short option is worth it. > > > > > > I agree. > > > > > > > 2. This might be controversial, but ability to do -Wno-error, would be great. > > > > Problem is we don't have categorized/named warnings/errors. But I think > > > > that it could support a syntax where we use file name (or partial match on > > > > its path) and disable warnings-as-errors for that source file. Or this > > > > might be even easier to implement: regex for warning message. It it > > > > matches, it won't be treated as an error. > > > > > > That sounds like an interesting idea - but maybe as a follow-up of this though? > > > > > > > 3. Exit code only change won't force developers to immediately fix their code > > > > as it's really easy to ignore in interactive terminals. Sure, later CI > > > > would catch it, but I would prefer early fail if possible. > > > > > > That's true - however, I checked again, and error messages originating from > > > bb.error (or bberror) do NOT stop the execution of bitbake. This is the role of > > > bb.fatal (or bbfatal). bb.error only affects the return code of bitbake, but > > > goes as far as possible - for example I was able to build an image recipe even > > > though one of its recipes emitted a bb.error. > > > > > > So if we want warnings to act like errors, I think this is already what this > > > series does. If we want warnings/errors to act like bb.fatal, that's another > > > question. > > > > I should also mention that ERROR_QA and WARN_QA allow many warnings to > > actually become errors. That is the mechanism we should really be > > pointing people at if they want errors IMO... > > Sure, but this couldn't possibly cover all warnings? No, it doesn't. People are often solving subtly different problems though and those give a different set of controls. > Maybe I can reword the intent of this series: give users an easy way of knowing > when one or more warnings were emitted so that they look at them instead of > ignoring them. > > Whether we should stop bitbake immediately on a warning or not seems to be > another question as per my previous email. Stopping immediately probably irritates users. We get into subtle problems though as if you continue and let the task get marked as success, the next build won't show the error. Even a clean build with existing sstate can not show warnings which were shown the first time. Including warnings in the sstate objects works to a point, for the warnings on the sstate task specifically, but what if those warnings come from an intermediate task like do_install? Those wouldn't get captured anywhere even if we have sstate warnings :(. > From your answers, I'm not really sure of whether you approve or deny of this > idea though. Should I send a v2 with a long option only (--fail-on-warnings), > and keep the rest as-is? I'm torn. If we do something, I do want the design to be consistent and for the behaviour to be really clear. I'm therefore trying to show the different corner cases I can think of. I don't have a good idea of what the end result should look like, I do know it needs thought which I don't really have the time to d justice myself :(. If we don't do that, there will just be a stream of patches, each subtly changing the behaviour to match what a given user wants at the expense of others. Cheers, Richard
diff --git a/lib/bb/ui/knotty.py b/lib/bb/ui/knotty.py index 1a3198b5c02..a3a5c374a35 100644 --- a/lib/bb/ui/knotty.py +++ b/lib/bb/ui/knotty.py @@ -662,6 +662,14 @@ def main(server, eventHandler, params, tf = TerminalFilter): # terminal handler console_handlers = [h for h in conf.config['handlers'].values() if getattr(h, 'is_console', False)] + if params.werror: + # Change the color of warning/warnonce messages to red when -W is passed + for h in console_handlers: + try: + h.formatter.set_warn_color_red() + except AttributeError: + pass + bb.utils.set_process_name("KnottyUI") if params.options.remote_server and params.options.kill_server: @@ -782,6 +790,8 @@ def main(server, eventHandler, params, tf = TerminalFilter): return_value = 1 elif event.levelno == bb.msg.BBLogFormatter.WARNING: warnings = warnings + 1 + if params.werror: + return_value = 1 if event.taskpid != 0: # For "normal" logging conditions, don't show note logs from tasks @@ -1054,6 +1064,10 @@ def main(server, eventHandler, params, tf = TerminalFilter): if return_value and errors: summary += pluralise("\nSummary: There was %s ERROR message, returning a non-zero exit code.", "\nSummary: There were %s ERROR messages, returning a non-zero exit code.", errors) + + if params.werror and warnings: + summary += "\nSummary: Warnings were treated as errors (-W)." + if summary and params.options.quiet == 0: print(summary)
When -W is passed, modify the handlers to show warnings in red and set the return value to 1. Add a summary line informing the user that the -W option was used as it might not be obvious when looking at the bottom the end of the console log. Signed-off-by: Antonin Godard <antonin.godard@bootlin.com> --- lib/bb/ui/knotty.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+)