mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
parttool: Avoid unnecessary exception backtrace for legitimate errors
Previous version used exception handling for program control flow, which makes for long and confusing backtrace messages if an error occurs while parsing the CSV (as it also prints the phony error that occurred while trying to parse as a binary, then prints "During handling of the above exception, another exception occurred:", then prints the real error). Use the same heuristic that is applied in gen_esp32_part, instead. Also, avoid printing the entire backtrace if the error is a gen_esp32_part InputError, same as gen_esp32part does. Found while looking into https://github.com/espressif/esp-idf/issues/4474
This commit is contained in:
parent
08219f3cf5
commit
bdb0851065
@ -93,10 +93,13 @@ class ParttoolTarget():
|
||||
self.esptool_erase_args = parse_esptool_args(esptool_erase_args)
|
||||
|
||||
if partition_table_file:
|
||||
try:
|
||||
with open(partition_table_file, "rb") as f:
|
||||
partition_table = None
|
||||
with open(partition_table_file, "rb") as f:
|
||||
input_is_binary = (f.read(2) == gen.PartitionDefinition.MAGIC_BYTES)
|
||||
if input_is_binary:
|
||||
partition_table = gen.PartitionTable.from_binary(f.read())
|
||||
except (gen.InputError, IOError, TypeError):
|
||||
|
||||
if partition_table is None:
|
||||
with open(partition_table_file, "r") as f:
|
||||
f.seek(0)
|
||||
partition_table = gen.PartitionTable.from_csv(f.read())
|
||||
@ -331,7 +334,11 @@ def main():
|
||||
except Exception:
|
||||
sys.exit(2)
|
||||
else:
|
||||
op(**common_args)
|
||||
try:
|
||||
op(**common_args)
|
||||
except gen.InputError as e:
|
||||
print(e, file=sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user