Skip to content

feat(ffi): surface auth connect errors in language wrappers#1692

Merged
kixelated merged 1 commit into
mainfrom
fix/wrapper-auth-errors
Jun 16, 2026
Merged

feat(ffi): surface auth connect errors in language wrappers#1692
kixelated merged 1 commit into
mainfrom
fix/wrapper-auth-errors

Conversation

@kixelated

Copy link
Copy Markdown
Collaborator

Follow-up to #1649, which added Unauthorized (HTTP 401) and Forbidden (HTTP 403) variants to the moq-ffi MoqError so callers can distinguish an auth rejection from a retryable transport failure. That PR landed the Rust side but left the language wrappers without an ergonomic way to act on the new variants (the Cross-Package Sync row for rs/moq-ffi). This closes that gap.

Summary

Parity helpers next to the existing isShutdown:

  • SwiftMoqError.isAuth (true for .Unauthorized / .Forbidden)
  • KotlinMoqException.isAuth
  • Gomoq.IsAuthError(err), using errors.Is over the generated ErrMoqErrorUnauthorized / ErrMoqErrorForbidden sentinels
  • Python — re-export MoqError from the moq package so callers can except moq.MoqError.Unauthorized without reaching into moq_ffi

Plus an auth-error note in each wrapper's guide (doc/lib/{swift,kt,go,py}) and the C library doc (doc/lib/c), which documents the distinct return codes + moq_error() strings since libmoq has no named C constants for them.

The variants themselves are already emitted by every binding (flat UniFFI error), so this is purely the ergonomic + documentation surface.

Test plan

  • CI just ci runs just {py,kt,go} check on the Linux runner (these wrappers were skipped for fix(native): surface terminal auth connect errors #1649 since it didn't touch them); Go compiles IsAuthError against freshly-regenerated bindings that now include ErrMoqErrorForbidden.
  • swift check is macOS-only and skips on the Linux runner; the isAuth helper mirrors the existing isShutdown exactly.
  • gofmt clean; Python isort/__all__ ordering consistent with existing style.

(Written by Claude)

The moq-ffi MoqError gained Unauthorized (HTTP 401) and Forbidden (HTTP 403)
variants so callers can tell an auth rejection from a retryable transport
failure, but the language wrappers didn't expose an ergonomic way to act on
them. Add parity helpers next to the existing isShutdown:

- swift: MoqError.isAuth
- kotlin: MoqException.isAuth
- go: moq.IsAuthError (errors.Is over the generated sentinels)
- python: re-export MoqError from the moq package

Document the auth-error path in each wrapper's guide plus the C library doc.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kixelated
kixelated force-pushed the fix/wrapper-auth-errors branch from b7cd320 to 49640b2 Compare June 12, 2026 16:50
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9c5f81ef-e71c-4052-920d-92c14409746b

📥 Commits

Reviewing files that changed from the base of the PR and between b7cd320 and 49640b2.

📒 Files selected for processing (9)
  • doc/lib/c/index.md
  • doc/lib/go/moq.md
  • doc/lib/kt/moq.md
  • doc/lib/py/moq-rs.md
  • doc/lib/swift/moq.md
  • go/moq/errors.go
  • kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Errors.kt
  • py/moq-rs/moq/__init__.py
  • swift/Sources/Moq/Errors.swift
✅ Files skipped from review due to trivial changes (5)
  • doc/lib/kt/moq.md
  • doc/lib/go/moq.md
  • doc/lib/c/index.md
  • doc/lib/swift/moq.md
  • doc/lib/py/moq-rs.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • py/moq-rs/moq/init.py
  • swift/Sources/Moq/Errors.swift
  • go/moq/errors.go
  • kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Errors.kt

Walkthrough

This PR adds authentication/authorization error handling guidance and helpers across the Moq SDK ecosystem. Implementations in Go, Kotlin, and Swift each provide an isAuth or IsAuthError convenience helper to detect HTTP 401/403 rejections, which are marked as terminal and non-retryable. Python's MoqError is exported in the public API to enable direct exception handling. All language bindings include documentation with code examples demonstrating how to distinguish authentication failures from transient transport errors, prompting for new credentials instead of reconnecting.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(ffi): surface auth connect errors in language wrappers' accurately summarizes the main change—adding ergonomic helpers and documentation to expose authentication/authorization errors in language wrappers.
Description check ✅ Passed The description clearly relates to the changeset, explaining the motivation (follow-up to #1649), the specific changes across all four language wrappers (Swift, Kotlin, Go, Python) and C documentation, and the test plan.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/wrapper-auth-errors

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kixelated

Copy link
Copy Markdown
Collaborator Author

@Qizot do you need this?

@Qizot

Qizot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

@kixelated yes, please

@kixelated
kixelated merged commit e6cacf5 into main Jun 16, 2026
1 check passed
@kixelated
kixelated deleted the fix/wrapper-auth-errors branch June 16, 2026 03:25
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