diff --git a/pdoc/cli.py b/pdoc/cli.py index d3d3316e..c074cd54 100755 --- a/pdoc/cli.py +++ b/pdoc/cli.py @@ -419,14 +419,11 @@ def to_url_id(module): json_values = [dict(obj, url=urls[obj['url']]) for obj in index] cmd = ['node', str(Path(__file__).with_name('build-index.js'))] - proc = subprocess.Popen(cmd, text=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) - main_path = args.output_dir - if proc.poll() is None: + try: + proc = subprocess.Popen(cmd, text=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) stdout, stderr = proc.communicate(json.dumps(json_values)) assert proc.poll() == 0, proc.poll() - if proc.returncode == 0: - stdout = 'INDEX=' + stdout - else: + except Exception: warn(f'Prebuilding Lunr index with command `{" ".join(cmd)}` failed: ' f'{proc.stderr and proc.stderr.read() or ""!r}. ' f'The search feature will still work, ' @@ -435,6 +432,9 @@ def to_url_id(module): f'pdoc environment.', category=RuntimeWarning) stdout = ('URLS=' + json.dumps(urls, indent=0, separators=(',', ':')) + ';\nINDEX=' + json.dumps(index, indent=0, separators=(',', ':'))) + else: + stdout = 'INDEX=' + stdout + main_path = args.output_dir index_path = Path(main_path).joinpath('index.js') index_path.write_text(stdout) print(str(index_path))