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

Improve error checking #24

Merged
merged 4 commits into from
Jan 22, 2019
Merged

Improve error checking #24

merged 4 commits into from
Jan 22, 2019

Conversation

dmjones
Copy link
Contributor

@dmjones dmjones commented Jan 21, 2019

The test code had very little error checking, which would make integration experiments difficult to grok. There were also places in the main code that ignored errors. This has also been addressed in this change.

The most interesting part of this is the deprecation of PKCS11Session.Close(). This function ignores the errors from the underlying library, which is unfortunate. There's no way to change this in a backwards-compatible fashion, so I've deprecated it and create an alternative function.

Duncan Jones added 3 commits January 21, 2019 13:13
The PKCS11Session.Close() method was ignoring the error return from the
PKCS#11 library. Impossible to fix this without breaking existing code,
so this function is deprecated and the awkwardly named CloseSession()
succeeds it.
Copy link
Contributor

@nickrmc83 nickrmc83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! We should - if we've not done so already - create an issue for creating a version which include our proposed breaking changes.

@dmjones dmjones merged commit 2abc075 into master Jan 22, 2019
@dmjones dmjones deleted the improve-error-checking branch January 22, 2019 12:01
file, err := os.Open(configLocation)
if err != nil {
log.Printf("Could not open config file: %s", configLocation)
return nil, err
}
defer file.Close()
defer func() {
err = file.Close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't look right. Suppose the file contents are malformed. Decode below will return a non-nil error and try to return it, but file.Close() will return nil. The result will be that ConfigureFromFile returns nil despite an error having occurred.

See https://play.golang.org/p/rzTxJM85e0c for a reduced example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes, good spot. I'll take a look for other places I may have introduced the same bug with this pattern. Thanks :-)

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

Successfully merging this pull request may close these issues.

3 participants