binman: Don't generate an error in 'text' entry constructor
authorSimon Glass <sjg@chromium.org>
Fri, 26 Apr 2019 03:58:33 +0000 (21:58 -0600)
committerBin Meng <bmeng.cn@gmail.com>
Wed, 8 May 2019 04:44:07 +0000 (12:44 +0800)
It is not good practice to raise an exception in a constructor. In this
case the 'text' entry may not actually be used, if -i is used to filter
out the images that get built.

Move the exception to where the data is actually used.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
tools/binman/etype/text.py

index 6e99819487faab75b2a2d7ded198f1b48987369e..c4aa510a87b855ba5fb6bc0bc642e8ee08eed92b 100644 (file)
@@ -51,10 +51,10 @@ class Entry_text(Entry):
         self.text_label, = self.GetEntryArgsOrProps(
             [EntryArg('text-label', str)])
         self.value, = self.GetEntryArgsOrProps([EntryArg(self.text_label, str)])
+
+    def ObtainContents(self):
         if not self.value:
             self.Raise("No value provided for text label '%s'" %
                        self.text_label)
-
-    def ObtainContents(self):
         self.SetContents(self.value)
         return True