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

fix: fix detect of ErrKeyNotFound error on non-english windows system #79

Merged
merged 1 commit into from Mar 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions wincred.go
Expand Up @@ -4,10 +4,14 @@ package keyring

import (
"strings"
"syscall"

"github.com/danieljoos/wincred"
)

// ERROR_NOT_FOUND from https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--1000-1299-
const elementNotFoundError = syscall.Errno(1168)
Alexey19 marked this conversation as resolved.
Show resolved Hide resolved

type windowsKeyring struct {
name string
prefix string
Expand Down Expand Up @@ -35,7 +39,7 @@ func init() {
func (k *windowsKeyring) Get(key string) (Item, error) {
cred, err := wincred.GetGenericCredential(k.credentialName(key))
if err != nil {
if err.Error() == "Element not found." {
if err == elementNotFoundError {
return Item{}, ErrKeyNotFound
}
return Item{}, err
Expand Down Expand Up @@ -65,7 +69,7 @@ func (k *windowsKeyring) Set(item Item) error {
func (k *windowsKeyring) Remove(key string) error {
cred, err := wincred.GetGenericCredential(k.credentialName(key))
if err != nil {
if err.Error() == "Element not found." {
if err == elementNotFoundError {
return ErrKeyNotFound
}
return err
Expand Down