@@ -103,7 +103,8 @@ impl FunChildren {
103103 /// provided function.
104104 pub fn wait_with_pipe ( & mut self , f : & mut dyn FnMut ( Box < dyn Read > ) ) -> CmdResult {
105105 let child = self . children . pop ( ) . unwrap ( ) ;
106- let stderr_thread = StderrThread :: new ( & child. cmd , child. stderr , false ) ;
106+ let stderr_thread =
107+ StderrThread :: new ( & child. cmd , & child. file , child. line , child. stderr , false ) ;
107108 match child. handle {
108109 CmdChildHandle :: Proc ( mut proc) => {
109110 if let Some ( stdout) = child. stdout {
@@ -145,6 +146,8 @@ impl FunChildren {
145146pub ( crate ) struct CmdChild {
146147 handle : CmdChildHandle ,
147148 cmd : String ,
149+ file : String ,
150+ line : u32 ,
148151 stdout : Option < PipeReader > ,
149152 stderr : Option < PipeReader > ,
150153}
@@ -153,10 +156,14 @@ impl CmdChild {
153156 pub ( crate ) fn new (
154157 handle : CmdChildHandle ,
155158 cmd : String ,
159+ file : String ,
160+ line : u32 ,
156161 stdout : Option < PipeReader > ,
157162 stderr : Option < PipeReader > ,
158163 ) -> Self {
159164 Self {
165+ file,
166+ line,
160167 handle,
161168 cmd,
162169 stdout,
@@ -165,8 +172,9 @@ impl CmdChild {
165172 }
166173
167174 fn wait ( mut self , is_last : bool ) -> CmdResult {
168- let _stderr_thread = StderrThread :: new ( & self . cmd , self . stderr . take ( ) , false ) ;
169- let res = self . handle . wait ( & self . cmd ) ;
175+ let _stderr_thread =
176+ StderrThread :: new ( & self . cmd , & self . file , self . line , self . stderr . take ( ) , false ) ;
177+ let res = self . handle . wait ( & self . cmd , & self . file , self . line ) ;
170178 if let Err ( e) = res {
171179 if is_last || process:: pipefail_enabled ( ) {
172180 return Err ( e) ;
@@ -184,7 +192,13 @@ impl CmdChild {
184192 }
185193
186194 fn wait_with_all ( mut self , capture : bool ) -> ( CmdResult , FunResult , FunResult ) {
187- let mut stderr_thread = StderrThread :: new ( & self . cmd , self . stderr . take ( ) , capture) ;
195+ let mut stderr_thread = StderrThread :: new (
196+ & self . cmd ,
197+ & self . file ,
198+ self . line ,
199+ self . stderr . take ( ) ,
200+ capture,
201+ ) ;
188202 let stdout_output = {
189203 if let Some ( mut out) = self . stdout . take ( ) {
190204 let mut s = String :: new ( ) ;
@@ -202,7 +216,7 @@ impl CmdChild {
202216 }
203217 } ;
204218 let stderr_output = stderr_thread. join ( ) ;
205- let res = self . handle . wait ( & self . cmd ) ;
219+ let res = self . handle . wait ( & self . cmd , & self . file , self . line ) ;
206220 ( res, stdout_output, stderr_output)
207221 }
208222
@@ -222,17 +236,19 @@ pub(crate) enum CmdChildHandle {
222236}
223237
224238impl CmdChildHandle {
225- fn wait ( self , cmd : & str ) -> CmdResult {
239+ fn wait ( self , cmd : & str , file : & str , line : u32 ) -> CmdResult {
226240 match self {
227241 CmdChildHandle :: Proc ( mut proc) => {
228242 let status = proc. wait ( ) ;
229243 match status {
230- Err ( e) => return Err ( process:: new_cmd_io_error ( & e, cmd) ) ,
244+ Err ( e) => return Err ( process:: new_cmd_io_error ( & e, cmd, file , line ) ) ,
231245 Ok ( status) => {
232246 if !status. success ( ) {
233247 return Err ( Self :: status_to_io_error (
234248 status,
235249 & format ! ( "Running [{cmd}] exited with error" ) ,
250+ file,
251+ line,
236252 ) ) ;
237253 }
238254 }
@@ -243,13 +259,15 @@ impl CmdChildHandle {
243259 match status {
244260 Ok ( result) => {
245261 if let Err ( e) = result {
246- return Err ( process:: new_cmd_io_error ( & e, cmd) ) ;
262+ return Err ( process:: new_cmd_io_error ( & e, cmd, file , line ) ) ;
247263 }
248264 }
249265 Err ( e) => {
250266 return Err ( Error :: new (
251267 ErrorKind :: Other ,
252- format ! ( "Running [{cmd}] thread joined with error: {e:?}" ) ,
268+ format ! (
269+ "Running [{cmd}] thread joined with error: {e:?} at {file}:{line}"
270+ ) ,
253271 ) )
254272 }
255273 }
@@ -259,11 +277,17 @@ impl CmdChildHandle {
259277 Ok ( ( ) )
260278 }
261279
262- fn status_to_io_error ( status : ExitStatus , cmd : & str ) -> Error {
280+ fn status_to_io_error ( status : ExitStatus , run_cmd : & str , file : & str , line : u32 ) -> Error {
263281 if let Some ( code) = status. code ( ) {
264- Error :: new ( ErrorKind :: Other , format ! ( "{cmd}; status code: {code}" ) )
282+ Error :: new (
283+ ErrorKind :: Other ,
284+ format ! ( "{run_cmd}; status code: {code} at {file}:{line}" ) ,
285+ )
265286 } else {
266- Error :: new ( ErrorKind :: Other , format ! ( "{cmd}; terminated by {status}" ) )
287+ Error :: new (
288+ ErrorKind :: Other ,
289+ format ! ( "{run_cmd}; terminated by {status} at {file}:{line}" ) ,
290+ )
267291 }
268292 }
269293
@@ -288,10 +312,12 @@ impl CmdChildHandle {
288312struct StderrThread {
289313 thread : Option < JoinHandle < String > > ,
290314 cmd : String ,
315+ file : String ,
316+ line : u32 ,
291317}
292318
293319impl StderrThread {
294- fn new ( cmd : & str , stderr : Option < PipeReader > , capture : bool ) -> Self {
320+ fn new ( cmd : & str , file : & str , line : u32 , stderr : Option < PipeReader > , capture : bool ) -> Self {
295321 if let Some ( stderr) = stderr {
296322 let thread = std:: thread:: spawn ( move || {
297323 let mut output = String :: new ( ) ;
@@ -312,11 +338,15 @@ impl StderrThread {
312338 } ) ;
313339 Self {
314340 cmd : cmd. into ( ) ,
341+ file : file. into ( ) ,
342+ line,
315343 thread : Some ( thread) ,
316344 }
317345 } else {
318346 Self {
319347 cmd : cmd. into ( ) ,
348+ file : file. into ( ) ,
349+ line,
320350 thread : None ,
321351 }
322352 }
@@ -326,10 +356,12 @@ impl StderrThread {
326356 if let Some ( thread) = self . thread . take ( ) {
327357 match thread. join ( ) {
328358 Err ( e) => {
329- let cmd = & self . cmd ;
330359 return Err ( Error :: new (
331360 ErrorKind :: Other ,
332- format ! ( "Running [{cmd}] stderr thread joined with error: {e:?}" , ) ,
361+ format ! (
362+ "Running [{}] stderr thread joined with error: {:?} at {}:{}" ,
363+ self . cmd, e, self . file, self . line
364+ ) ,
333365 ) ) ;
334366 }
335367 Ok ( output) => return Ok ( output) ,
0 commit comments