diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-11-23 09:03:57 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-11-23 13:39:34 +0000 |
commit | e2bd9d6ec51036f13ac5b0f9a17c9d85a1eb0125 (patch) | |
tree | a28cccea7974d77e1cc2efb5bd141ddd4bcb42d1 | |
parent | f786e915f2f26785de87672788e47a1ddee0332c (diff) |
example_gallery: Improve error handling
Print error messages about invalid JSON project files and decoding
errors caused by binary files. Treat .jpg files as binary files.
Change-Id: I3d40789fc4680c7f2918a7a23c3d4fcc98ce9f81
Reviewed-by: Christian Tismer <tismer@stackless.com>
(cherry picked from commit ab8d43efb06ad00f8be945efde7a11279eda44fa)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | tools/example_gallery/main.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/tools/example_gallery/main.py b/tools/example_gallery/main.py index d6ca7b827..f19b530b3 100644 --- a/tools/example_gallery/main.py +++ b/tools/example_gallery/main.py @@ -152,7 +152,7 @@ def get_code_tabs(files, project_file): for i, project_file in enumerate(files): pfile = Path(project_file) - if pfile.suffix in (".png", ".pyc"): + if pfile.suffix in (".jpg", ".png", ".pyc"): continue content += f".. tabbed:: {project_file}\n\n" @@ -163,8 +163,12 @@ def get_code_tabs(files, project_file): _path = f_path.resolve().parents[0] / project_file _file_content = "" - with open(_path, "r") as _f: - _file_content = remove_licenses(_f.read()) + try: + with open(_path, "r") as _f: + _file_content = remove_licenses(_f.read()) + except UnicodeDecodeError as e: + print(f"example_gallery: error decoding {_path}:{e}") + raise content += add_indent(_file_content, 2) content += "\n\n" @@ -259,8 +263,12 @@ if __name__ == "__main__": ) pyproject = "" - with open(str(f_path), "r") as pyf: - pyproject = json.load(pyf) + try: + with open(str(f_path), "r") as pyf: + pyproject = json.load(pyf) + except json.JSONDecodeError as e: + print(f"example_gallery: error reading {f_path}: {e}") + raise if pyproject: rst_file_full = EXAMPLES_DOC / rst_file |