Skip to content

Commit 70ac6af

Browse files
noneymousUllaakut
andauthored
Fixed issue with latest return error handling (#139)
Co-authored-by: Brendan Le Glaunec <brendan@glaulabs.com>
1 parent 8a507e4 commit 70ac6af

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

nmap.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,22 @@ func (s *Scanner) processNmapResult(result *Run, warnings *[]string, stdout, std
264264

265265
// Check for errors indicated by context or return code.
266266
switch {
267-
case errors.Is(s.ctx.Err(), context.DeadlineExceeded):
267+
case errors.Is(s.ctx.Err(), context.DeadlineExceeded): // Command context exceeded
268268
return ErrScanTimeout
269-
case errors.Is(s.ctx.Err(), context.Canceled):
269+
case errors.Is(s.ctx.Err(), context.Canceled): // Command context cancelled programmatically
270270
return ErrScanInterrupt
271-
case errStatus.Error() == "exit status 0xc000013a": // Exit code for ctrl+c on Windows
272-
return ErrScanInterrupt
273-
case errStatus.Error() == "exit status 130": // Exit code for ctrl+c on Linux
274-
return ErrScanInterrupt
275-
// TODO: Add clauses for other known exit codes we might want to define closer.
276-
case errStatus != nil
277-
return errStatus
271+
case errStatus != nil: // Error with status code returned by Nmap
272+
273+
// Return suitable error or pass through original exit status
274+
switch {
275+
case errStatus.Error() == "exit status 0xc000013a": // Exit code for ctrl+c on Windows
276+
return ErrScanInterrupt
277+
case errStatus.Error() == "exit status 130": // Exit code for ctrl+c on Linux
278+
return ErrScanInterrupt
279+
// TODO: Add clauses for other known exit codes we might want to define closer.
280+
default:
281+
return errStatus
282+
}
278283
default:
279284
}
280285

0 commit comments

Comments
 (0)