* [PATCH] lib/qa.py: raise ValueError if file isn't an ELF
@ 2016-02-15 17:50 Ross Burton
2016-02-15 23:30 ` Phil Blundell
0 siblings, 1 reply; 2+ messages in thread
From: Ross Burton @ 2016-02-15 17:50 UTC (permalink / raw)
To: openembedded-core
Instead of raising a generic Exception that can't be handled specifically, raise
a ValueError. Also update the callers so any unexpected exceptions are not
ignored.
Also, rename isBigEngian() to isBigEndian().
Signed-off-by: Ross Burton <ross.burton@intel.com>
---
meta/classes/insane.bbclass | 2 +-
meta/classes/uninative.bbclass | 2 +-
meta/lib/oe/qa.py | 14 +++++++-------
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/meta/classes/insane.bbclass b/meta/classes/insane.bbclass
index 530e711..a76f8dd 100644
--- a/meta/classes/insane.bbclass
+++ b/meta/classes/insane.bbclass
@@ -792,7 +792,7 @@ def package_qa_walk(warnfuncs, errorfuncs, skip, package, d):
elf = oe.qa.ELFFile(path)
try:
elf.open()
- except:
+ except ValueError:
elf = None
for func in warnfuncs:
func(path, package, d, elf, warnings)
diff --git a/meta/classes/uninative.bbclass b/meta/classes/uninative.bbclass
index 0448cf6..b14cec0 100644
--- a/meta/classes/uninative.bbclass
+++ b/meta/classes/uninative.bbclass
@@ -80,7 +80,7 @@ python uninative_changeinterp () {
elf = oe.qa.ELFFile(f)
try:
elf.open()
- except:
+ except ValueError:
continue
#bb.warn("patchelf-uninative --set-interpreter %s %s" % (d.getVar("UNINATIVE_LOADER", True), f))
diff --git a/meta/lib/oe/qa.py b/meta/lib/oe/qa.py
index 21fb997..2ad6c63 100644
--- a/meta/lib/oe/qa.py
+++ b/meta/lib/oe/qa.py
@@ -23,7 +23,7 @@ class ELFFile:
def my_assert(self, expectation, result):
if not expectation == result:
#print "'%x','%x' %s" % (ord(expectation), ord(result), self.name)
- raise Exception("This does not work as expected")
+ raise ValueError("%s is not an ELF" % self.name)
def __init__(self, name, bits = 0):
self.name = name
@@ -32,7 +32,7 @@ class ELFFile:
def open(self):
if not os.path.isfile(self.name):
- raise Exception("File is not a normal file")
+ raise ValueError("%s is not a normal file" % self.name)
self.file = file(self.name, "r")
self.data = self.file.read(ELFFile.EI_NIDENT+4)
@@ -49,24 +49,24 @@ class ELFFile:
self.bits = 64
else:
# Not 32-bit or 64.. lets assert
- raise Exception("ELF but not 32 or 64 bit.")
+ raise ValueError("ELF but not 32 or 64 bit.")
elif self.bits == 32:
self.my_assert(self.data[ELFFile.EI_CLASS], chr(ELFFile.ELFCLASS32))
elif self.bits == 64:
self.my_assert(self.data[ELFFile.EI_CLASS], chr(ELFFile.ELFCLASS64))
else:
- raise Exception("Must specify unknown, 32 or 64 bit size.")
+ raise ValueError("Must specify unknown, 32 or 64 bit size.")
self.my_assert(self.data[ELFFile.EI_VERSION], chr(ELFFile.EV_CURRENT) )
self.sex = self.data[ELFFile.EI_DATA]
if self.sex == chr(ELFFile.ELFDATANONE):
- raise Exception("self.sex == ELFDATANONE")
+ raise ValueError("self.sex == ELFDATANONE")
elif self.sex == chr(ELFFile.ELFDATA2LSB):
self.sex = "<"
elif self.sex == chr(ELFFile.ELFDATA2MSB):
self.sex = ">"
else:
- raise Exception("Unknown self.sex")
+ raise ValueError("Unknown self.sex")
def osAbi(self):
return ord(self.data[ELFFile.EI_OSABI])
@@ -80,7 +80,7 @@ class ELFFile:
def isLittleEndian(self):
return self.sex == "<"
- def isBigEngian(self):
+ def isBigEndian(self):
return self.sex == ">"
def machine(self):
--
2.7.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] lib/qa.py: raise ValueError if file isn't an ELF
2016-02-15 17:50 [PATCH] lib/qa.py: raise ValueError if file isn't an ELF Ross Burton
@ 2016-02-15 23:30 ` Phil Blundell
0 siblings, 0 replies; 2+ messages in thread
From: Phil Blundell @ 2016-02-15 23:30 UTC (permalink / raw)
To: Ross Burton; +Cc: openembedded-core
On Mon, 2016-02-15 at 17:50 +0000, Ross Burton wrote:
> Instead of raising a generic Exception that can't be handled specifically, raise
> a ValueError.
If what you want is an exception to mean "this file isn't actually ELF",
how about defining a new exception class InvalidElfError or something
and raising that? ValueError still seems a bit vague for what you are
trying to do.
p.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-02-15 23:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-15 17:50 [PATCH] lib/qa.py: raise ValueError if file isn't an ELF Ross Burton
2016-02-15 23:30 ` Phil Blundell
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.