colcon / colcon-core

Command line tool to build sets of software packages
http://colcon.readthedocs.io
Apache License 2.0
107 stars 47 forks source link

colcon swallows failure details in shell extension #371

Open rotu opened 4 years ago

rotu commented 4 years ago

I expect to see useful failure information (e.g. stdout and stderr of the failed command, or even whether the target script exists) but colcon does not expose this info. It instead shows only the python stack trace which contains no actionable details.

  Starting >>> test_rclcpp
  [2245.139s] colcon.colcon_core.shell ERROR Exception in shell extension 'bat': Expected ['D:\\a\\colcon-cmake\\colcon-cmake\\ros_ws\\build\\test_rclcpp\\colcon_command_prefix_build.bat', '&&', 'set'] to pass
  Traceback (most recent call last):
    File "c:\hostedtoolcache\windows\python\3.7.8\x64\lib\site-packages\colcon_core\shell\__init__.py", line 289, in get_command_environment
      task_name, Path(build_base), dependencies)
    File "c:\hostedtoolcache\windows\python\3.7.8\x64\lib\site-packages\colcon_core\shell\bat.py", line 128, in generate_command_environment
      env = await get_environment_variables(cmd, cwd=str(build_base))
    File "c:\hostedtoolcache\windows\python\3.7.8\x64\lib\site-packages\colcon_core\shell\__init__.py", line 325, in get_environment_variables
      output = await check_output(cmd, cwd=cwd, shell=shell)
    File "c:\hostedtoolcache\windows\python\3.7.8\x64\lib\site-packages\colcon_core\subprocess.py", line 106, in check_output
      assert not rc, 'Expected {args} to pass'.format_map(locals())
  AssertionError: Expected ['D:\\a\\colcon-cmake\\colcon-cmake\\ros_ws\\build\\test_rclcpp\\colcon_command_prefix_build.bat', '&&', 'set'] to pass

  [2245.139s] colcon.colcon_cmake.task.cmake.build ERROR Could not find a shell extension for the command environment
  Failed   <<< test_rclcpp  [ Exited with code 1 ]

https://github.com/rotu/colcon-cmake/runs/1029201058?check_suite_focus=true#step:17:15262

dirk-thomas commented 4 years ago

Please provide reproducible steps.

rotu commented 4 years ago

Run this on a windows runner: https://github.com/rotu/colcon-cmake/actions/runs/224539412/workflow

dirk-thomas commented 4 years ago

Please provide more minimal steps which only involve the pieces necessary to reproduce the problem locally.

rotu commented 4 years ago

Sure. Just edit a shell hook to have a syntax error and observe that there is no debug info to speak of. The Python stack trace here should be suppressed as well, since the Python code is working as intended.

rotu commented 4 years ago

I may be naive. It seems that batch scripts don’t have “stack traces” as other languages do. The best solution for batch might just be to run the script with echo on and print the output if the script fails.

dirk-thomas commented 4 years ago

I expect to see useful failure information (e.g. stdout and stderr of the failed command, or even whether the target script exists) but colcon does not expose this info.

assert not rc, 'Expected {args} to pass'.format_map(locals())

You seem to be using an older version of colcon-core. The current code already includes the stderr output (even though that might or might not contain valuable information): https://github.com/colcon/colcon-core/blob/caee5e64608912f52e86f79de1cf53b8c34713df/colcon_core/subprocess.py#L109-L110. This has been added in #353.

The Python stack trace here should be suppressed as well, since the Python code is working as intended.

The Python exception is only visible error that something went wrong. I don't see how you could distinguish a failure caused by some colcon code vs. package specific content. And for the former case the stack trace is essential in debugging. If you have a specific proposal how to do better please feel free to describe it (or even better contribute a pull request).

Please re-run your use case with an up-to-date colcon-core package and share the resulting error message to determine if this can be closed.