objcerrors

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Rendered for darwin/amd64

Overview

Package objcerrors provides ObjCError, a structured Go error that preserves the full diagnostic payload of an Objective-C NSError: domain, code, localized strings, and any chain of underlying errors.

Generated bindings surface errors through [pureobjc.NSErrorToError], which returns an *ObjCError wrapped as the error interface. Callers that need structured access use errors.As:

var e *objcerrors.ObjCError
if errors.As(err, &e) {
    log.Printf("domain=%s code=%d reason=%s", e.Domain, e.Code, e.FailureReason)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CFErrorToError

func CFErrorToError(ptr unsafe.Pointer) error

CFErrorToError converts a CFErrorRef out-parameter to a Go error.

CFError is toll-free bridged with NSError at the ObjC runtime level. Casting the CFErrorRef pointer to objc.ID and calling NSError methods via objc.Send works without any CGo or C shim — the ObjC runtime dispatches to the correct implementation through the toll-free bridge.

Returns nil if ptr is nil (no error was set by the callee).

Types

type ObjCError

type ObjCError struct {
	// Domain is the NSError error domain string, e.g. "VZErrorDomain" or
	// "NSPOSIXErrorDomain". Together with Code it uniquely identifies the error kind.
	Domain string

	// Code is the numeric error code within the domain.
	Code int64

	// Description is the localizedDescription — the primary human-readable message.
	Description string

	// FailureReason is the localizedFailureReason — a more specific explanation of
	// why the operation failed. Empty if the NSError did not supply one.
	FailureReason string

	// RecoverySuggestion is the localizedRecoverySuggestion — what the user or
	// caller could do to resolve the error. Empty if the NSError did not supply one.
	RecoverySuggestion string

	// Underlying holds errors from the NSError underlyingErrors array (macOS 11.3+).
	// Nil when the error has no underlying causes.
	Underlying []*ObjCError
}

ObjCError is a structured Go error wrapping an Objective-C NSError.

Domain and Code together are the machine-readable identity of the error and are stable across OS versions. The string fields are for human display only and may be localised. Use errors.As to access these fields programmatically.

func New

func New(id objc.ID) *ObjCError

New converts an NSError ObjC object to an *ObjCError, extracting all available diagnostic fields. Returns nil if id is zero (no error).

func (*ObjCError) Error

func (e *ObjCError) Error() string

Error implements the error interface. The string includes the domain, code, and all non-empty localized strings so it is immediately useful in log output without requiring a separate errors.As call.

func (*ObjCError) Unwrap

func (e *ObjCError) Unwrap() []error

Unwrap returns the slice of underlying errors so that errors.Is and errors.As traverse the full error tree. Returns nil when there are none.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL