Skip to content

Include class name in non-parcelable args error message#733

Merged
elihart merged 1 commit intoairbnb:mainfrom
Dwite:Dwite/args-error-class-name
Jan 28, 2026
Merged

Include class name in non-parcelable args error message#733
elihart merged 1 commit intoairbnb:mainfrom
Dwite:Dwite/args-error-class-name

Conversation

@Dwite
Copy link
Copy Markdown
Contributor

@Dwite Dwite commented Jan 24, 2026

Summary

When args passed to a ViewModel are neither Parcelable nor Serializable, the error message now includes the class name to help developers quickly identify which class needs to be fixed.

Before:

java.lang.IllegalStateException: Args must be parcelable or serializable

After:

java.lang.IllegalStateException: Args must be parcelable or serializable. Class com.example.MyArgs is neither.

Motivation

This change addresses a debugging pain point where the existing error message doesn't indicate which class is causing the exception. When an app has multiple ViewModels with different args types, identifying the problematic class requires manual investigation.

This follows the same pattern as commit e920c4b which improved error messages in PersistState.kt for similar serialization issues.

Changes

  • MavericksViewModelProvider.kt: Updated error message to include ${args::class.java.name}
  • ArgsTest.kt: Added test testNonParcelableArgsErrorContainsClassName to verify the error message contains the class name

Test plan

  • Added unit test that verifies the error message contains the class name
  • All existing tests pass (./gradlew :mvrx:test)

When args passed to a ViewModel are neither Parcelable nor Serializable,
the error message now includes the class name to help developers quickly
identify which class needs to be fixed.

Before: "Args must be parcelable or serializable"
After:  "Args must be parcelable or serializable. Class com.example.MyArgs is neither."

This follows the same pattern as commit e920c4b which improved error
messages in PersistState.kt.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Dwite Dwite force-pushed the Dwite/args-error-class-name branch from b092056 to 987d4c5 Compare January 24, 2026 22:04
Copy link
Copy Markdown
Contributor

@elihart elihart left a comment

Choose a reason for hiding this comment

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

Nice addition, thanks!

@elihart elihart merged commit a37016d into airbnb:main Jan 28, 2026
6 checks passed
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