Skip to content

darwin: return ATT errors as AttributeProtocolError - #499

Merged
deadprogram merged 2 commits into
devfrom
darwin-att-errors
Oct 9, 2026
Merged

deadprogram merged 2 commits into
devfrom
darwin-att-errors

Conversation

@acouvreur

Copy link
Copy Markdown
Member

Fixes #498

Read, Write and EnableNotifications on macOS now return an ATT error from the peripheral as AttributeProtocolError, using the error domain that tinygo-org/cbgo#20 adds. Errors in other domains, such as CBErrorDomain, are returned unchanged.

Draft until cbgo has a release with tinygo-org/cbgo#20. Until then go.mod points at that PR's commit. Updating cbgo also raises golang.org/x/crypto, x/sys and x/term, which cbgo master already requires.

Tested on macOS 15.7.7 against an ESP32-S3 peripheral. A write the peripheral rejects with Invalid PDU now returns AttributeProtocolError 0x04 instead of a *cbgo.NSError. The smoketest-macos builds pass, and so do the TinyGo builds for pca10040-s132v6, pca10056-s140v7, nano-rp2040 and pico-w.

@deadprogram

Copy link
Copy Markdown
Member

Thank you. tinygo-org/cbgo#20 is merged and tagged as v0.1.0. Please change go.mod to github.com/tinygo-org/cbgo v0.1.0, run go mod tidy, and mark this PR as ready for review. The current version points at a commit that is only on the nserror-domain branch.

@acouvreur
acouvreur marked this pull request as ready for review October 9, 2026 15:53

@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.

Looking good @acouvreur thanks! Now merging.

cbgo v0.1.0 adds NSError.Domain. It also requires golang.org/x/crypto
v0.26.0, which raises x/crypto, x/sys and x/term here.
An ATT error from the peripheral reached the caller as a *cbgo.NSError,
with a localized message and a code that is ambiguous without its
domain. Read, Write and EnableNotifications now return errors in
CBATTErrorDomain as AttributeProtocolError. Errors in other domains are
returned unchanged.
@deadprogram
deadprogram merged commit 8e7be8f into dev Oct 9, 2026
4 checks passed
@deadprogram
deadprogram deleted the darwin-att-errors branch October 9, 2026 17:52
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.

darwin: ATT errors are returned as cbgo.NSError instead of AttributeProtocolError

2 participants