diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-11-23 09:03:57 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-11-23 11:24:55 +0100 |
| commit | ab8d43efb06ad00f8be945efde7a11279eda44fa (patch) | |
| tree | 8f0e3099227c6549740db4e658b0be1e651f43fa | |
| parent | b70f82fdf4a733448003ff692f2cbce149d275af (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.
Pick-to: 6.2
Change-Id: I3d40789fc4680c7f2918a7a23c3d4fcc98ce9f81
Reviewed-by: Christian Tismer <tismer@stackless.com>
| -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 |
