diff mbox

[4/4] classes/core: runstrip() print error if filtype can not be determined

Message ID ddbecd1163c731b4025e3690ceb00f9b226b4438.1350473427.git.morten.thunbergsvendsen@prevas.dk
State Accepted
Delegated to: Esben Haabendal
Headers show

Commit Message

Morten Svendsen Oct. 17, 2012, 11:33 a.m. UTC
Prints readable error message instead of the following:
   File "/src/oe-lite/meta/core/classes/core.oeclass", line 147, in runstrip
     if "not stripped" not in filetype:
TypeError: argument of type 'NoneType' is not iterable

The actual cause of this error is unknown. The magic python module do not raise
an exception when file is not readable, but returns a NoneType object 'None'.
---
 classes/core.oeclass |    4 ++++
 1 file changed, 4 insertions(+)

Comments

Esben Haabendal Oct. 22, 2012, 4:12 p.m. UTC | #1
Morten Thunberg Svendsen <morten.thunbergsvendsen@prevas.dk> writes:

> Prints readable error message instead of the following:
>    File "/src/oe-lite/meta/core/classes/core.oeclass", line 147, in runstrip
>      if "not stripped" not in filetype:
> TypeError: argument of type 'NoneType' is not iterable
>
> The actual cause of this error is unknown. The magic python module do not raise
> an exception when file is not readable, but returns a NoneType object 'None'.
> ---
>  classes/core.oeclass |    4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/classes/core.oeclass b/classes/core.oeclass
> index 33dfe22..9de03fc 100644
> --- a/classes/core.oeclass
> +++ b/classes/core.oeclass
> @@ -144,6 +144,10 @@ def runstrip(file, d):
>      filemagic.load()
>      filetype = filemagic.file(file)
>  
> +    if not filetype:
> +        bb.error("runstrip() unable to determine file type: %s"%(file))
> +        return
> +
>      if "not stripped" not in filetype:
>          print "runstrip() skip %s"%(file)
>          return

Merged to master and 3.2 branch.

/Esben
diff mbox

Patch

diff --git a/classes/core.oeclass b/classes/core.oeclass
index 33dfe22..9de03fc 100644
--- a/classes/core.oeclass
+++ b/classes/core.oeclass
@@ -144,6 +144,10 @@  def runstrip(file, d):
     filemagic.load()
     filetype = filemagic.file(file)
 
+    if not filetype:
+        bb.error("runstrip() unable to determine file type: %s"%(file))
+        return
+
     if "not stripped" not in filetype:
         print "runstrip() skip %s"%(file)
         return