Skip to content

fix: replace panic with error return in archive function#705

Merged
danielpaulus merged 3 commits into
danielpaulus:mainfrom
mvanhorn:osc/179-remove-panic-archive
Jun 5, 2026
Merged

fix: replace panic with error return in archive function#705
danielpaulus merged 3 commits into
danielpaulus:mainfrom
mvanhorn:osc/179-remove-panic-archive

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces the panic() in archive() with a proper error return. The function now returns ([]interface{}, plist.UID, error) instead of panicking on unsupported object types.

Why this matters

Issue #179 flags panic() usage in library code. The maintainer pointed to archiver.go:76 as a good starting PR. Panics in library code crash the calling application instead of letting it handle the error gracefully.

Changes

  • ios/nskeyedarchiver/archiver.go: Changed archive(), serializeArray(), serializeMutableArray(), serializeSet(), and serializeMap() signatures to return error. Replaced panic at line 83 with fmt.Errorf.
  • ios/nskeyedarchiver/objectivec_classes.go: Updated all callers of archive() to propagate errors.

Testing

  • Verified Go compilation passes for ./ios/nskeyedarchiver/... and ./ios/...

Fixes #179

This contribution was developed with AI assistance (Codex).

Changes the archive() function signature to return an error instead of
panicking on unsupported object types. Propagates the error through all
internal callers (serializeArray, serializeMutableArray, serializeSet,
serializeMap) and the external caller in objectivec_classes.go.

Fixes danielpaulus#179

@danielpaulus danielpaulus left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Reviewed the panic-to-error conversion and pushed a maintainer follow-up that adds regression coverage for unsupported archive input, including nil. Local verification passed: go test ./ios/nskeyedarchiver, go test ./..., and make build GO_IOS_BINARY_NAME=/tmp/go-ios-pr705-build NCM_BINARY_NAME=/tmp/go-ncm-pr705-build. GitHub currently reports no checks for this fork branch.

@danielpaulus danielpaulus merged commit 0b02015 into danielpaulus:main Jun 5, 2026
@mvanhorn

mvanhorn commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @danielpaulus! Returning an error instead of panicking in archive should be friendlier to embedders.

@danielpaulus

Copy link
Copy Markdown
Owner

Thanks @danielpaulus! Returning an error instead of panicking in archive should be friendlier to embedders.

Yes indeed! Go-ios should never panic! Thanks for fixing it 👍👍

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks for the merge, @danielpaulus. Archive errors propagating instead of panicking should make automation around it much calmer.

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.

Remove panic() from the codebase

2 participants