Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
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

code quality #18

Closed
petar-dambovaliev opened this issue Oct 13, 2019 · 0 comments
Closed

code quality #18

petar-dambovaliev opened this issue Oct 13, 2019 · 0 comments

Comments

@petar-dambovaliev
Copy link
Contributor

petar-dambovaliev commented Oct 13, 2019

Please, fix these nested if-else statements.
Early returns are much easier to read.
An example of that would be in the control.go file with the error handling.
If there is no error, the length of the data is acceptable and everything is okay, it seems that this will always return an error.

if err == nil {
		if length := len(response.Data); length > 18 { // 18 is the minimum expected
			if int(response.Data[19]) != pduStart {
				err = fmt.Errorf(ErrorText(errCliCannotStartPLC))
			} else {
				if int(response.Data[20]) == pduAlreadyStarted {
					err = fmt.Errorf(ErrorText(errCliAlreadyRun))
				} else {
					err = fmt.Errorf(ErrorText(errCliCannotStartPLC))
				}
			}
		} else {
			err = fmt.Errorf(ErrorText(errIsoInvalidPDU))
		}
	}

Also, there are mistakes in the Stop method.
int(response.Data[20]) == pduAlreadyStarted
Should be
int(response.Data[20]) == pduAlreadyStopped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant