Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Ed Bartosh <ed.bartosh@linux.intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [wic][PATCH] wic: refactored processing of wic exceptions
Date: Wed, 27 May 2015 14:05:20 +0300	[thread overview]
Message-ID: <1432724720-7255-1-git-send-email-ed.bartosh@linux.intel.com> (raw)

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>
---
 scripts/lib/wic/utils/errors.py | 34 ++++++++--------------------------
 scripts/wic                     | 11 +++++------
 2 files changed, 13 insertions(+), 32 deletions(-)

diff --git a/scripts/lib/wic/utils/errors.py b/scripts/lib/wic/utils/errors.py
index 9410311..d1b514d 100644
--- a/scripts/lib/wic/utils/errors.py
+++ b/scripts/lib/wic/utils/errors.py
@@ -16,32 +16,14 @@
 # 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
diff --git a/scripts/wic b/scripts/wic
index 90b36c6..cf96859 100755
--- a/scripts/wic
+++ b/scripts/wic
@@ -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)
 
-- 
2.1.4



                 reply	other threads:[~2015-05-27 12:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1432724720-7255-1-git-send-email-ed.bartosh@linux.intel.com \
    --to=ed.bartosh@linux.intel.com \
    --cc=openembedded-core@lists.openembedded.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