Patchwork [1/2] classes/patch: avoid backtrace when patch does not apply

login
register
mail settings
Submitter Paul Eggleton
Date Jan. 19, 2012, 1:59 p.m.
Message ID <592d932934f891f3f73dc9630fa9d1a7d94aff56.1326981479.git.paul.eggleton@linux.intel.com>
Download mbox | patch
Permalink /patch/19785/
State Accepted
Commit ce6c80a1e68c2af0b4b5fa27582ad9c9f119e5c1
Headers show

Comments

Paul Eggleton - Jan. 19, 2012, 1:59 p.m.
We don't need to see a Python stack backtrace when a patch does not
apply, just the error output from patch, so trap these kinds of errors
and ensure that we display the message and fail the task and nothing
else.

Fixes [YOCTO #1143]

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
---
 meta/classes/patch.bbclass |    5 ++++-
 meta/lib/oe/patch.py       |   10 +++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)
Richard Purdie - Jan. 19, 2012, 2:32 p.m.
On Thu, 2012-01-19 at 13:59 +0000, Paul Eggleton wrote:
> We don't need to see a Python stack backtrace when a patch does not
> apply, just the error output from patch, so trap these kinds of errors
> and ensure that we display the message and fail the task and nothing
> else.
> 
> Fixes [YOCTO #1143]
> 
> Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
> ---
>  meta/classes/patch.bbclass |    5 ++++-
>  meta/lib/oe/patch.py       |   10 +++++-----
>  2 files changed, 9 insertions(+), 6 deletions(-)

Merged to master, thanks.

Richard

Patch

diff --git a/meta/classes/patch.bbclass b/meta/classes/patch.bbclass
index 471c32b..1ea4bc5 100644
--- a/meta/classes/patch.bbclass
+++ b/meta/classes/patch.bbclass
@@ -155,7 +155,10 @@  python patch_do_patch() {
 			patchset.Import({"file":local, "strippath": parm['striplevel']}, True)
 		except Exception as exc:
 			bb.fatal(str(exc))
-		resolver.Resolve()
+		try:
+			resolver.Resolve()
+		except bb.BBHandledException as e:
+			bb.fatal(str(e))
 }
 patch_do_patch[vardepsexclude] = "PATCHRESOLVE"
 
diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index f4ccb3e..6f7f900 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -2,14 +2,14 @@  import oe.path
 import os
 import bb.utils, bb.msg, bb.data, bb.fetch2
 
-class NotFoundError(Exception):
+class NotFoundError(bb.BBHandledException):
     def __init__(self, path):
         self.path = path
 
     def __str__(self):
         return "Error: %s not found." % self.path
 
-class CmdError(Exception):
+class CmdError(bb.BBHandledException):
     def __init__(self, exitstatus, output):
         self.status = exitstatus
         self.output = output
@@ -207,7 +207,7 @@  class QuiltTree(PatchSet):
         # read series -> self.patches
         seriespath = os.path.join(self.dir, 'patches', 'series')
         if not os.path.exists(self.dir):
-            raise Exception("Error: %s does not exist." % self.dir)
+            raise NotFoundError(self.dir)
         if os.path.exists(seriespath):
             series = file(seriespath, 'r')
             for line in series.readlines():
@@ -228,7 +228,7 @@  class QuiltTree(PatchSet):
                 if sys.exc_value.output.strip() == "No patches applied":
                     return
                 else:
-                    raise sys.exc_value
+                    raise
             output = [val for val in output.split('\n') if not val.startswith('#')]
             for patch in self.patches:
                 if os.path.basename(patch["quiltfile"]) == output[-1]:
@@ -336,7 +336,7 @@  class NOOPResolver(Resolver):
         except Exception:
             import sys
             os.chdir(olddir)
-            raise sys.exc_value
+            raise
 
 # Patch resolver which relies on the user doing all the work involved in the
 # resolution, with the exception of refreshing the remote copy of the patch