Bug 4491 - improve the definition of bb.fatal()
Summary: improve the definition of bb.fatal()
Status: VERIFIED NOTABUG
Alias: None
Product: BitBake
Classification: Build System, Metadata & Runtime
Component: bitbake (show other bugs)
Version: 1.5
Hardware: x86 Multiple
: Medium enhancement
Target Milestone: 1.5 M2
Assignee: Robert Yang
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2013-05-13 09:27 UTC by Robert Yang
Modified: 2013-10-03 14:57 UTC (History)
5 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: No (bug/feature does not impact docs)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Yang 2013-05-13 09:27:18 UTC
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...
Comment 1 Robert Yang 2013-05-13 09:30:27 UTC
We may also change the currently "bb.fatal(...)" to raise "bb.Fatal(...)"
Comment 2 Robert Yang 2013-06-17 09:15:29 UTC
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).
Comment 3 Robert Yang 2013-08-13 01:47:18 UTC
Please see the previous comments.
Comment 4 Stoicescu Cornel 2013-10-03 14:57:02 UTC
Marking as Verified as per above comments..