]> code.ossystems Code Review - openembedded-core.git/commitdiff
wic: refactored processing of wic exceptions
authorEd Bartosh <ed.bartosh@linux.intel.com>
Wed, 27 May 2015 11:05:20 +0000 (14:05 +0300)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 27 May 2015 16:44:44 +0000 (17:44 +0100)
All wic exceptions are now inherited from new base exception
class WicError. It makes them easy to maintain and catch.

Processing of exceptions is done this way:
    Known wic exceptions cause wic to print error message to stdout.
    Unknown exceptions are not catched anymore and produce standard
    python traceback.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
scripts/lib/wic/utils/errors.py
scripts/wic

index 9410311875a2235f0135b40615f269b048204cac..d1b514dd9d176b0020326574c056673934b73655 100644 (file)
 # with this program; if not, write to the Free Software Foundation, Inc., 59
 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-class CreatorError(Exception):
-    """An exception base class for all imgcreate errors."""
-    keyword = '<creator>'
+class WicError(Exception):
+    pass
 
-    def __init__(self, msg):
-        self.msg = msg
+class CreatorError(WicError):
+    pass
 
-    def __str__(self):
-        if isinstance(self.msg, unicode):
-            self.msg = self.msg.encode('utf-8', 'ignore')
-        else:
-            self.msg = str(self.msg)
-        return self.keyword + self.msg
+class Usage(WicError):
+    pass
 
-class Usage(CreatorError):
-    keyword = '<usage>'
-
-    def __str__(self):
-        if isinstance(self.msg, unicode):
-            self.msg = self.msg.encode('utf-8', 'ignore')
-        else:
-            self.msg = str(self.msg)
-        return self.keyword + self.msg + ', please use "--help" for more info'
-
-class KsError(CreatorError):
-    keyword = '<kickstart>'
-
-class ImageError(CreatorError):
-    keyword = '<mount>'
+class ImageError(WicError):
+    pass
index 90b36c68acf616252fab4bb6f9098ab09c58f2a1..cf968591e26f134d934ed4abe72420636d533dad 100755 (executable)
@@ -53,6 +53,7 @@ else:
     bitbake_main = None
 
 from wic.utils.oe.misc import find_bitbake_env_lines, set_bitbake_env_lines
+from wic.utils.errors import WicError
 from image import engine
 from image import help as hlp
 
@@ -309,10 +310,8 @@ def main(argv):
 
 if __name__ == "__main__":
     try:
-        ret = main(sys.argv[1:])
-    except Exception:
-        ret = 1
-        import traceback
-        traceback.print_exc()
-    sys.exit(ret)
+        sys.exit(main(sys.argv[1:]))
+    except WicError as err:
+        print >> sys.stderr, "ERROR:", err
+        sys.exit(1)