Skip to content

Commit

Permalink
Merge pull request #79 from Alexey19/fix_bug_with_l18n
Browse files Browse the repository at this point in the history
fix: fix detect of ErrKeyNotFound error on non-english windows system
  • Loading branch information
mtibben committed Mar 24, 2021
2 parents 7209b11 + 83d1e2c commit d9b6b92
Showing 1 changed file with 6 additions and 2 deletions.
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)

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

0 comments on commit d9b6b92

Please sign in to comment.