Skip to content

core: keep the NSError domain - #20

Merged
deadprogram merged 1 commit into
masterfrom
nserror-domain
Oct 9, 2026
Merged

deadprogram merged 1 commit into
masterfrom
nserror-domain

Conversation

@acouvreur

Copy link
Copy Markdown
Member

NSError kept the code and localized description of an error but not its domain. CoreBluetooth reuses the same numbers across domains, so the code can't be interpreted without it: 4 is an invalid ATT PDU in CBATTErrorDomain and out of space in CBErrorDomain.

This carries the domain through bt_error and adds NSError.Domain.

Needed for tinygo-org/bluetooth#498, so the darwin backend can return ATT errors as AttributeProtocolError.

Tested on macOS 15.7.7 against an ESP32-S3 peripheral. A write the peripheral rejects with Invalid PDU now reports domain CBATTErrorDomain and code 4. go build and go vet pass.

NSError kept the code and localized description of an error but not its
domain. The code means little without it, because CoreBluetooth reuses
the same numbers across domains: 4 is an invalid ATT PDU in
CBATTErrorDomain and out of space in CBErrorDomain, and 15 is
insufficient encryption in one and encryption timed out in the other.

Carry the domain through bt_error and add NSError.Domain.

@deadprogram deadprogram left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. This is needed for tinygo-org/bluetooth#499.

@deadprogram
deadprogram merged commit 99bd5f7 into master Oct 9, 2026
1 check passed
@deadprogram
deadprogram deleted the nserror-domain branch October 9, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants