From 83d1e2cad85eae9574bb0e9c8acd6663bd6f5cb2 Mon Sep 17 00:00:00 2001 From: Alexey Tyuryumov Date: Fri, 5 Mar 2021 12:03:04 -0700 Subject: [PATCH] fix: fix detect of ErrKeyNotFound error on non-english windows system --- wincred.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wincred.go b/wincred.go index b3dc01a..18ccbfa 100644 --- a/wincred.go +++ b/wincred.go @@ -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 @@ -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 @@ -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