-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error handling difficult and not reliable #38
Comments
Sample code to split errors/warnings from stderr:
|
It MIGHT be that we discover some warnings which we cannot clearly identify as warnings. I think the suggested solution still is the best one, because it also gives a lot of flexibility. People can decide to ignore certain errors or even all of them. If the XML parses, they can use it. Furthermore, I think we need to take it step by step and improve the solution incrementally. |
Here the python nmap package for reference. Although, I think this is not the best code. |
After looking more into it, I'm slowly coming to the conclusion that anything on stderr should be undestood as a warning and everyboody should check these "warnings" for things they care about. If something is critical, Nmap returns valid XML but with the attribute E.g. Nmap may write "Error resolving name" to stderr. It can either be a warning or a critical message. It is a warning if a scan target (hostname) could not be resolved. It is critical if it's a host from the exclude file that could not be resolved. In both cases Nmap will write the same message to stderr. But only in the second case the Nmap XML output contains status=error and an error message. Additionally the message "QUITTING" can be found on stderr. |
Fixing "Error handling difficult and not reliable #38"
Issue
It is currently difficult to check whether an Nmap scan failed, due to two reasons:
Examples generated by Run():
Examples returned via stderr:
Example found in result.Stats.Finished.ErrorMsg:
Suggestion
I'm suggesting to change the signature of the Run() method to:
func (s *Scanner) Run() (*Run, []strings, []error) { }
This is a breaking change on purpose. It will prevent people from compiling their old code with the updated package. We do not want to affect their application behaviour without them noticing. Ideally, they should reconsider their error handling too.
With this suggestion we can return an intuitive set of result data: result, list of warnings and list of errors.
=> Result may exist as soon as the XML could be parsed (even if there are errors returned in parallel)
=> Warnings may be there and can be used if desired.
=> The list of errors can aggregate the error messages from our run method, stderr and a copy of those from the xml output.
Possible Implementation
Really really nice to have
I'ts tricky, but mybe we want to introdcue (more) error constants (in errors.go) for whatever we run across. So that other developers directly are aware of them and can handle them as they need.
The text was updated successfully, but these errors were encountered: