Skip to content

fix: Align errorMessage param type in validate and requireNotNull as same as their suspend counterparts#628

Open
Vijay0710 wants to merge 1 commit into
skydoves:mainfrom
Vijay0710:fix/align-validate-requirenotnull
Open

fix: Align errorMessage param type in validate and requireNotNull as same as their suspend counterparts#628
Vijay0710 wants to merge 1 commit into
skydoves:mainfrom
Vijay0710:fix/align-validate-requirenotnull

Conversation

@Vijay0710

@Vijay0710 Vijay0710 commented May 30, 2026

Copy link
Copy Markdown

🎯 Goal

validate and requireNotNull accepted a lazy lambda crossinline errorMessage: () -> String
while their suspend counterparts suspendValidate and suspendRequireNotNull accepted a plain
String. This inconsistency made the API surface asymmetric and the existing KDocs actively
misleading — they still described errorMessage as a lambda even after the implementation
diverged. This PR aligns the non-suspend functions with the suspend ones and corrects the stale
documentation.

🛠 Implementation details

  • Changed errorMessage in validate and requireNotNull from
    crossinline errorMessage: () -> String to errorMessage: String
  • Removed the now-redundant callsInPlace(errorMessage, ...) contract clause from both functions
  • Fixed @param errorMessage KDoc in validate: was "A lambda that provides the error message
    when validation fails"
    → now "The error message when validation fails."
  • Fixed @param errorMessage KDoc in requireNotNull: was "A lambda that provides the error
    message when the selected value is null"
    → now "The error message when the selected value
    is null."
  • Updated call sites in ResponseTransformerTest from trailing lambda syntax to plain String
  • Regenerated .api dump files via ./gradlew apiDump

✍️ Explain examples

Before:

apiResponse.validate({ it.length > 2 }) { "Too short" }
apiResponse.requireNotNull({ it.field }) { "Value is null" }

After:

apiResponse.validate({ it.length > 2 }, errorMessage = "Too short")
apiResponse.requireNotNull({ it.field }, "Value is null")

// Suspend variants were already consistent — unchanged:
apiResponse.suspendValidate({ it.length > 2 }, "Too short")
apiResponse.suspendRequireNotNull({ it.field }, "Value is null")

@Vijay0710 Vijay0710 requested a review from skydoves as a code owner May 30, 2026 19:31
@Vijay0710 Vijay0710 changed the title fix: correct KDoc and align errorMessage param type in validate and requireNotNull fix: Align errorMessage param type in validate and requireNotNull as same as their suspend counterparts May 30, 2026
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.

1 participant