huawei-noah / SMARTS

Scalable Multi-Agent RL Training School for Autonomous Driving
MIT License
944 stars 190 forks source link

Scenario build error message improvements #2055

Closed saulfield closed 1 year ago

saulfield commented 1 year ago

When an error is encountered while building a scenario, the error message can be cryptic because it is actually running a temp file, and the stack trace is noisy:

Building: scenarios/sumo/loop/
Traceback (most recent call last):
  File "tmpjv0_4z2_.py", line 14, in <module>
    traffic = t.Traffic(
NameError: name 't' is not defined
Traceback (most recent call last):
  File "/home/saul/code/SMARTS/.venv/bin/scl", line 8, in <module>
    sys.exit(scl())
  File "/home/saul/code/SMARTS/.venv/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/saul/code/SMARTS/.venv/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/saul/code/SMARTS/.venv/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/saul/code/SMARTS/.venv/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/saul/code/SMARTS/.venv/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/saul/code/SMARTS/.venv/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/saul/code/SMARTS/cli/studio.py", line 55, in build
    build_scenario(scenario=scenario, clean=clean, seed=seed, log=click.echo)
  File "/home/saul/code/SMARTS/smarts/sstudio/scenario_construction.py", line 62, in build_scenario
    subprocess.check_call(
  File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/saul/code/SMARTS/.venv/bin/python3.8', 'tmpjv0_4z2_.py']' returned non-zero exit status 1.

I changed it so that no temp file is created, and I trimmed the error message:

Building: scenarios/sumo/loop/
Traceback (most recent call last):
  File "scenario_builder.py", line 45, in <module>
    _build(args.scenario_py, args.seed)
  File "scenario_builder.py", line 33, in _build
    exec(code, {"__file__": scenario_py})
  File "/home/saul/code/SMARTS/scenarios/sumo/loop/scenario.py", line 9, in <module>
    traffic = t.Traffic(
NameError: name 't' is not defined
Command '['/home/saul/code/SMARTS/.venv/bin/python3.8', 'scenario_builder.py', '/home/saul/code/SMARTS/scenarios/sumo/loop/scenario.py', '42']' returned non-zero exit status 1.

We could remove even more of the error message if we want.