Skip to content

Commit c797c0b

Browse files
committed
Improve usability of error handling
1 parent 2c21df8 commit c797c0b

File tree

6 files changed

+20
-9
lines changed

6 files changed

+20
-9
lines changed

chipflow_lib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ def _parse_config() -> 'Config':
6868
except FileNotFoundError:
6969
raise ChipFlowError(f"Config file not found. I expected to find it at {config_file}")
7070
except tomli.TOMLDecodeError as e:
71-
raise ChipFlowError(f"TOML Error found when loading {config_file}: {e.msg} at line {e.lineno}, column {e.colno}")
71+
raise ChipFlowError(f"{config_file} has a formatting error: {e.msg} at line {e.lineno}, column {e.colno}")

chipflow_lib/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,6 @@ def run(argv=sys.argv[1:]):
113113
if hasattr(args, "action"):
114114
cmd += f" {args.action}"
115115
print(f"Error while executing `{cmd}`: {e}")
116+
print("Caused by:")
117+
traceback.print_exception(e.__cause__)
116118
exit(1)

chipflow_lib/platforms/_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ def top_components(config: 'Config') -> Dict[str, wiring.Component]:
11041104
logger.debug(f"Config {param} = {conf} found for {name}")
11051105
component_configs[param] = conf
11061106
if name.startswith('_'):
1107-
raise ChipFlowError(f"Top components cannot start with '_': {name}")
1107+
raise ChipFlowError(f"Top components cannot start with '_' character, these are reserved for internal use: {name}")
11081108

11091109
# Second pass: instantiate components
11101110
for name, ref in config.chipflow.top.items():
@@ -1114,7 +1114,7 @@ def top_components(config: 'Config') -> Dict[str, wiring.Component]:
11141114
result[name] = cls(component_configs[name])
11151115
else:
11161116
result[name] = cls()
1117-
logger.debug(f"top members for {name}:\n{pformat(result[name].metadata.origin.signature.members)}")
1117+
logger.debug(f"Top members for {name}:\n{pformat(result[name].metadata.origin.signature.members)}")
11181118

11191119
return result
11201120

chipflow_lib/platforms/silicon.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,16 @@ def _prepare(self, elaboratable, name="top"):
488488
return fragment.prepare(ports)
489489

490490
def build(self, elaboratable, name="top"):
491+
# hide Amaranth `UnusedElaboratable` warnings
491492
warnings.simplefilter(action="ignore", category=UnusedElaboratable)
492-
fragment = self._prepare(elaboratable, name)
493-
rtlil_text, _ = rtlil.convert_fragment(fragment, name)
493+
try:
494+
fragment = self._prepare(elaboratable, name)
495+
rtlil_text, _ = rtlil.convert_fragment(fragment, name)
496+
except Exception as e:
497+
raise ChipFlowError("Error found when building design.") from e
498+
499+
# Enable warnings when an exception hasn't occured
500+
warnings.filterwarnings("default", category=UnusedElaboratable)
494501

495502
# Integrate Amaranth design with external Verilog
496503
yosys_script = [

chipflow_lib/steps/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def _wire_up_ports(m: Module, top, platform):
5353
for n, t in top.items():
5454
logger.debug(f" > {n}, {t}")
5555
setattr(m.submodules, n, t)
56-
print("Wiring up ports:")
5756
for component, iface in platform._pinlock.port_map.ports.items():
5857
if component.startswith('_'):
5958
logger.debug(f"Ignoring special component {component}")

chipflow_lib/steps/silicon.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ def build_cli_parser(self, parser):
8282
submit_subparser = action_argument.add_parser(
8383
"submit", help=inspect.getdoc(self.submit).splitlines()[0]) # type: ignore
8484
submit_subparser.add_argument(
85-
"--dry-run", help=argparse.SUPPRESS,
85+
"--dry-run",
86+
help="Build but do not submit design to cloud. Will output `rtlil` and `config` files.",
8687
default=False, action="store_true")
8788
submit_subparser.add_argument(
88-
"--wait", help=argparse.SUPPRESS,
89+
"--wait",
90+
help="Maintain connection to cloud and trace build messages. Filtering is based on the log level (see `verbose` option).",
8991
default=False, action="store_true")
9092

9193
def run_cli(self, args):
@@ -172,10 +174,11 @@ def submit(self, rtlil_path, args):
172174
logger.debug(f"data=\n{json.dumps(data, indent=2)}")
173175
logger.debug(f"files['config']=\n{config}")
174176
shutil.copyfile(rtlil_path, 'rtlil')
175-
with open("data", 'w') as f:
177+
with open("rtlil", 'w') as f:
176178
json.dump(data, f)
177179
with open("config", 'w') as f:
178180
f.write(config)
181+
sp.info(f"Compiled design and configuration can be found in in `rtlil` and `config`")
179182
return
180183

181184
def network_err(e):

0 commit comments

Comments
 (0)