| Summary: | improve the definition of bb.fatal() | ||
|---|---|---|---|
| Product: | [Build System, Metadata & Runtime] BitBake | Reporter: | Robert Yang <liezhi.yang> |
| Component: | bitbake | Assignee: | Robert Yang <liezhi.yang> |
| Status: | VERIFIED NOTABUG | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | Medium | CC: | corneliux.stoicescu, poky.bs.watcher, poky.watcher, richard.purdie, sgw |
| Version: | 1.5 | ||
| Target Milestone: | 1.5 M2 | ||
| Hardware: | x86 | ||
| OS: | Multiple | ||
| Whiteboard: | |||
| OS type for building Yocto: | --- | Type of Regression: | --- |
| Verified: | Documentation change: | No (bug/feature does not impact docs) | |
We may also change the currently "bb.fatal(...)" to raise "bb.Fatal(...)" After more investigations, I'm sorry to say that I didn't see many benefits
of this change, the only one that you mentioned we can use "except SystemExit"
to handle the fatal error with the new code, but the "except SystemExit" also
works with the old code, e.g.:
import sys
try:
sys.exit(1)
except SystemExit:
print "Catch SystemExit"
And the new code uses:
SystemExit.__init__(self, 1, ''.join(*args))
which can raise more messages, but I think that we need the logger.critical()
here to log the messages in the log file, so we can only use
SystemExit.__init__(self, 1), it seems that it equals to sys.exit(1).
Please see the previous comments. Marking as Verified as per above comments.. |
Comments from Mike: I was actually more thinking like this (untested pseusocode follows): class Fatal(SystemExit): def __init__(self, *args): SystemExit.__init__(self, 1, ''.join(*args)) # or so def fatal(*args): 'For backward compatibility' raise Fatal(*args) New code should use "raise bb.Fatal(..)" instead of "fatal(..)". It has the added advantage of being able to explicitly catch and handle the Fatal error. Which could be useful in bitbake frontends. Inheriting from SystemExit makes it behave exactly like the old code in all ways, so it wouldn't break things. It makes it clear what happens. bb.fatal() is a function that doesn't really return. But it isn't as fatal as its name suggests, because it really just raises an exception, so anyone doing a catch or finally may be surprised by its implementation. Converting it into an exception makes it obvious to the world what it does without the need for documentation...