Skip to content

Commit 2775fe1

Browse files
committed
Better error messages
1 parent 0996470 commit 2775fe1

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

src/semiwrap/autowrap/context.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from dataclasses import dataclass, field
1414
import enum
15+
import pathlib
1516
import typing
1617

1718
from cxxheaderparser.types import Function, PQName
@@ -517,6 +518,9 @@ class HeaderContext:
517518
# Name in toml
518519
hname: str
519520

521+
# config file for this
522+
orig_yaml: pathlib.Path
523+
520524
extra_includes_first: typing.List[str]
521525
extra_includes: typing.List[str]
522526
inline_code: typing.Optional[str]
@@ -538,6 +542,9 @@ class HeaderContext:
538542
# same as classes, but only those that have trampolines
539543
classes_with_trampolines: typing.List[ClassContext] = field(default_factory=list)
540544

545+
# for diagnostic purposes
546+
ignored_classes: typing.List[str] = field(default_factory=list)
547+
541548
functions: typing.List[FunctionContext] = field(default_factory=list)
542549

543550
# trampolines

src/semiwrap/autowrap/cxxparser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ def on_class_start(self, state: AWClassBlockState) -> typing.Optional[bool]:
596596

597597
# Ignore explicitly ignored classes (including default-ignore)
598598
if class_data.ignore:
599+
self.hctx.ignored_classes.append(cls_key)
599600
return False
600601

601602
if missing and not self.report_only:
@@ -1999,6 +2000,7 @@ def parse_header(
19992000
# Initialize the header context with user configuration
20002001
hctx = HeaderContext(
20012002
hname=name,
2003+
orig_yaml=gendata.data_fname,
20022004
extra_includes_first=user_cfg.extra_includes_first,
20032005
extra_includes=user_cfg.extra_includes,
20042006
inline_code=user_cfg.inline_code,

src/semiwrap/cmd_dat2tmplcpp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def _write_wrapper_cpp(input_dat: pathlib.Path, py_name: str, output_cpp: pathli
2121
if tmpl.py_name == py_name:
2222
break
2323
else:
24-
raise ValueError(f"internal error: cannot find {py_name}")
24+
raise ValueError(f"internal error: cannot find {py_name} in {hctx.orig_yaml}")
2525

2626
content = render_template_inst_cpp(hctx, tmpl)
2727
output_cpp.write_text(content)

src/semiwrap/cmd_dat2trampoline.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,18 @@ def _write_wrapper_cpp(input_dat: pathlib.Path, yml_id: str, output_hpp: pathlib
3434
if cls.yml_id == yml_id:
3535
break
3636
else:
37-
avail = ", ".join(avail)
38-
raise ValueError(f"internal error: cannot find {yml_id} (found {avail})")
37+
msg = [
38+
f"cannot find {yml_id} in {hctx.rel_fname}",
39+
f"- config: {hctx.orig_yaml}",
40+
]
41+
42+
if avail:
43+
msg.append("- found " + ", ".join(avail))
44+
45+
if hctx.ignored_classes:
46+
msg.append("- ignored " + ", ".join(hctx.ignored_classes))
47+
48+
raise ValueError("\n".join(msg))
3949

4050
content = render_cls_rpy_include_hpp(hctx, cls)
4151
output_hpp.write_text(content)

0 commit comments

Comments
 (0)