Skip to content

Commit 9857b7f

Browse files
authored
Merge pull request #19 from vvoland/better-winreg-msg
winreg: Clearer device/controller not found message
2 parents 7cdb222 + 7d7c6a6 commit 9857b7f

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

winreg/winreg.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,13 @@ func createTmpCopy(path string) (*os.File, error) {
8888
// ```
8989
func (r *Registry) GetBluetoothLinkKey(controllerMAC, deviceMAC string) (string, error) {
9090
// Normalize MAC addresses to Windows format (lowercase, no colons)
91-
controllerMAC = normalizeMAC(controllerMAC)
92-
deviceMAC = normalizeMAC(deviceMAC)
93-
94-
scanner := bufio.NewScanner(bytes.NewReader(r.dump.Bytes()))
91+
searchSection := fmt.Sprintf("%s\\%s", "ControlSet001\\Services\\BTHPORT\\Parameters\\Keys", normalizeMAC(controllerMAC))
92+
searchDevice := fmt.Sprintf(`"%s"=hex:`, normalizeMAC(deviceMAC))
9593

9694
controllerFound := false
97-
searchSection := fmt.Sprintf("%s\\%s", "ControlSet001\\Services\\BTHPORT\\Parameters\\Keys", controllerMAC)
98-
searchDevice := fmt.Sprintf(`"%s"=hex:`, deviceMAC)
99-
10095
inSection := false
96+
97+
scanner := bufio.NewScanner(bytes.NewReader(r.dump.Bytes()))
10198
for scanner.Scan() {
10299
line := scanner.Text()
103100
line = strings.TrimSpace(line)
@@ -126,10 +123,10 @@ func (r *Registry) GetBluetoothLinkKey(controllerMAC, deviceMAC string) (string,
126123
}
127124

128125
if !controllerFound {
129-
return "", fmt.Errorf("controller not found in registry")
126+
return "", fmt.Errorf("controller (%s) not found in the Windows registry", controllerMAC)
130127
}
131128

132-
return "", fmt.Errorf("device not found in registry")
129+
return "", fmt.Errorf("device (%s) not found in the Windows registry", deviceMAC)
133130
}
134131

135132
func normalizeMAC(mac string) string {

winreg/winreg_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ func TestGetBluetoothLinkKey(t *testing.T) {
2626
name: "missing controller",
2727
controllerMAC: "ff:ee:dd:cc:bb:aa",
2828
deviceMAC: "aa:bb:cc:dd:ee:ff",
29-
expectedErr: "controller not found in registry",
29+
expectedErr: "controller (ff:ee:dd:cc:bb:aa) not found in the Windows registry",
3030
},
3131
{
3232
name: "missing device key",
3333
controllerMAC: "00:11:22:33:44:55",
3434
deviceMAC: "ff:ff:ff:ff:ff:ff",
35-
expectedErr: "device not found in registry",
35+
expectedErr: "device (ff:ff:ff:ff:ff:ff) not found in the Windows registry",
3636
},
3737
{
3838
name: "valid key",

0 commit comments

Comments
 (0)