Documentation
¶
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 ¶
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 ¶
New converts an NSError ObjC object to an *ObjCError, extracting all available diagnostic fields. Returns nil if id is zero (no error).