@@ -86,11 +86,11 @@ def execute(self) -> None:
8686
8787 running_tools [toolname ] = tool
8888
89- try :
90- # Tools can output to stdout/stderr in unexpected places, for example,
91- # pydocstyle emits warnings about __all__ and as pyroma exec's the setup.py
92- # file, it will execute any print statements in that, etc etc...
93- with CaptureOutput ( hide = not self . config . direct_tool_stdout ) as capture :
89+ # Tools can output to stdout/stderr in unexpected places, for example,
90+ # pydocstyle emits warnings about __all__ and as pyroma exec's the setup.py
91+ # file, it will execute any print statements in that, etc etc...
92+ with CaptureOutput ( hide = not self . config . direct_tool_stdout ) as capture :
93+ try :
9494 messages += tool .run (found_files )
9595
9696 if self .config .include_tool_stdout :
@@ -103,25 +103,33 @@ def execute(self) -> None:
103103 msg = f"stdout from { toolname } :\n { capture .get_hidden_stdout ()} "
104104 messages .append (Message (toolname , "hidden-output" , loc , message = msg ))
105105
106- except FatalProspectorException as fatal :
107- sys .stderr .write (f"FatalProspectorException: { str (fatal )} " )
108- sys .exit (2 )
109-
110- except (SystemExit , Exception ) as ex : # pylint:disable=broad-except
111- if self .config .die_on_tool_error :
112- raise FatalProspectorException (f"Tool { toolname } failed to run." ) from ex
113- loc = Location (self .config .workdir , None , None , None , None )
114- msg = (
115- f"Tool { toolname } failed to run "
116- f"(exception was raised, re-run prospector with -X to see the stacktrace)"
117- )
118- message = Message (
119- toolname ,
120- "failure" ,
121- loc ,
122- message = msg ,
123- )
124- messages .append (message )
106+ except FatalProspectorException as fatal :
107+ sys .stderr .write (f"FatalProspectorException: { str (fatal )} " )
108+ sys .exit (2 )
109+
110+ except (SystemExit , Exception ) as ex : # pylint:disable=broad-except
111+ stderr = capture .get_hidden_stderr ().strip ()
112+ if self .config .die_on_tool_error :
113+ msg = f"Tool { toolname } failed to run"
114+ if stderr :
115+ msg += ", with stderr:\n " + stderr
116+ else :
117+ msg += "."
118+ raise FatalProspectorException () from ex
119+ loc = Location (self .config .workdir , None , None , None , None )
120+
121+ msg = f"Tool { toolname } failed to run "
122+ if stderr :
123+ msg += f", with stderr:\n { stderr } \n "
124+ msg += "(exception was raised, re-run prospector with -X to see the stacktrace)\n "
125+
126+ message = Message (
127+ toolname ,
128+ "failure" ,
129+ loc ,
130+ message = msg ,
131+ )
132+ messages .append (message )
125133
126134 messages = self .process_messages (found_files , messages , running_tools )
127135
0 commit comments