From ca454c93d163a551f7f24baac41a3b29538860ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Tue, 3 Aug 2021 09:32:31 +0200 Subject: [PATCH] component_information: add debug instrumentation for FileNotFoundError exception The following exception occurs in some rare cases (but only with make build: NO_NINJA_BUILD=1 px4_sitl_default): Traceback (most recent call last): File "/__w/PX4-Autopilot/PX4-Autopilot/src/lib/component_information/generate_component_general.py", line 79, in save_compressed(filename) File "/__w/PX4-Autopilot/PX4-Autopilot/src/lib/component_information/generate_component_general.py", line 33, in save_compressed with open(filename, 'r') as content_file: FileNotFoundError: [Errno 2] No such file or directory: '/__w/PX4-Autopilot/PX4-Autopilot/build/px4_sitl_default/component_general.json' make[3]: *** [src/lib/component_information/CMakeFiles/component_information_header.dir/build.make:68: component_general.json] Error 1 --- .../generate_component_general.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib/component_information/generate_component_general.py b/src/lib/component_information/generate_component_general.py index 6b8f605913..d801940f03 100755 --- a/src/lib/component_information/generate_component_general.py +++ b/src/lib/component_information/generate_component_general.py @@ -4,6 +4,7 @@ import argparse import json import lzma #to create .xz file import re +import os parser = argparse.ArgumentParser(description="""Generate the COMPONENT_GENERAL json file""") parser.add_argument('filename', metavar='component_general.json', help='JSON output file') @@ -75,5 +76,14 @@ component_general['metadataTypes'] = metadata_types with open(filename, 'w') as outfile: json.dump(component_general, outfile) +# DEBUG: in some cases writing the compressed file fails with 'No such file or directory' +# even though it was just written above +if not os.path.isfile(filename): + print('{:} does not exist'.format(filename)) + if compress: - save_compressed(filename) + try: + save_compressed(filename) + except FileNotFoundError as e: + print(os.listdir(os.path.dirname(filename))) + raise