API behavior between backends (may not be) consistent
joemiller opened this issue · 2 comments
Example on first-use of an application:
- The macos keychain backend will return an empty list and nil error the first time Keys() (or Get()) is called:
2019/06/01 07:11:51 [keyring] Considering backends: [keychain pass file]
2019/06/01 07:11:51 [keyring] Querying keychain for service="vault", keychain=""
2019/06/01 07:11:51 [keyring] Found 0 results
$ echo $?
0
- The libsecret backend will return a secretError with message that the keychain does not exist:
2019/06/01 07:13:25 [keyring] Considering backends: [secret-service kwallet pass file]
Error: Failed to read tokens from backend storage: The collection "vault" does not exist. Please add a key first
$ echo $?
255
The returned error is a generic type secretError
and so I could handle this by wrapping keyring.List() and checking err.Error() contains the string "Please add a key first", but I am wondering what the expected behavior is for the library itself and if perhaps libsecret should be modified to not return an err if the collection does not yet exist?
I haven't checked the other backend types for how they handle first-use of Get and Keys yet.
kwallet
backend behavior on initial Get() or List() is to create the wallet and return nil error
Good question, I'd say Get()
should return either the item or ErrKeyNotFound
and List()
should return a nil slice and no error if there are no keys.