-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Improve error checking #24
Conversation
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.
There was a problem hiding this 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.
00f97c3
to
448ffac
Compare
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :-)
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.