mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Nicer reporting of errors when using geninclude
This commit is contained in:
@@ -189,6 +189,9 @@ class NamedLineIterator:
|
|||||||
return self.lines
|
return self.lines
|
||||||
|
|
||||||
|
|
||||||
|
class GenincludeError(Exception): ...
|
||||||
|
|
||||||
|
|
||||||
def pygeninclude(path: str) -> list[str]:
|
def pygeninclude(path: str) -> list[str]:
|
||||||
import io
|
import io
|
||||||
import runpy
|
import runpy
|
||||||
@@ -196,6 +199,12 @@ def pygeninclude(path: str) -> list[str]:
|
|||||||
buf = sys.stdout = io.StringIO()
|
buf = sys.stdout = io.StringIO()
|
||||||
try:
|
try:
|
||||||
runpy.run_path(path, run_name='__main__')
|
runpy.run_path(path, run_name='__main__')
|
||||||
|
except FileNotFoundError:
|
||||||
|
raise
|
||||||
|
except Exception:
|
||||||
|
import traceback
|
||||||
|
tb = traceback.format_exc()
|
||||||
|
raise GenincludeError(f'Running the geninclude program: {path} failed with the error:\n{tb}')
|
||||||
finally:
|
finally:
|
||||||
sys.stdout = before
|
sys.stdout = before
|
||||||
return buf.getvalue().splitlines()
|
return buf.getvalue().splitlines()
|
||||||
@@ -208,7 +217,9 @@ def geninclude(path: str) -> list[str]:
|
|||||||
if path.endswith('.py'):
|
if path.endswith('.py'):
|
||||||
return pygeninclude(path)
|
return pygeninclude(path)
|
||||||
import subprocess
|
import subprocess
|
||||||
cp = subprocess.run([path], stdout=subprocess.PIPE, text=True)
|
cp = subprocess.run([path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||||
|
if cp.returncode != 0:
|
||||||
|
raise GenincludeError(f'Running the geninclude program: {path} failed with exit code: {cp.returncode} and STDERR:\n{cp.stderr}')
|
||||||
return cp.stdout.splitlines()
|
return cp.stdout.splitlines()
|
||||||
finally:
|
finally:
|
||||||
if old is None:
|
if old is None:
|
||||||
@@ -281,8 +292,11 @@ def parse_line(
|
|||||||
if not memory.seen(val):
|
if not memory.seen(val):
|
||||||
try:
|
try:
|
||||||
lines = geninclude(val)
|
lines = geninclude(val)
|
||||||
except Exception:
|
except FileNotFoundError as e:
|
||||||
log_error(f'Could not process geninclude {val}, ignoring')
|
if e.filename == val:
|
||||||
|
log_error(f'Could not find the geninclude file: {val}, ignoring')
|
||||||
|
else:
|
||||||
|
raise
|
||||||
else:
|
else:
|
||||||
with currently_parsing.set_file(f'<get: {val}>'):
|
with currently_parsing.set_file(f'<get: {val}>'):
|
||||||
_parse(
|
_parse(
|
||||||
|
|||||||
Reference in New Issue
Block a user