Skip to content

Standardize Result return type in favor of sometimes throwing and sometimes returning null #469

@cameronvoell

Description

@cameronvoell

Is your feature request related to a problem?

  1. If we throw an exception when no Dm found, the return type does not need to be nullable
  2. For functions that are expected to throw in expected cases like when an id isn't found (not an unexpected error) we should markup with @throws OR consider setting the return type to Result so that integrators know they should explicitly handle exceptions in these cases.
    fun findDmByInboxId(inboxId: InboxId): Dm? {
        return try {
            Dm(client, ffiClient.dmConversation(inboxId))
        } catch (e: Exception) {
            null
        }
    }

    suspend fun findDmByIdentity(publicIdentity: PublicIdentity): Dm? {
        val inboxId =
            client.inboxIdFromIdentity(publicIdentity)
                ?: throw XMTPException("No inboxId present")
        return findDmByInboxId(inboxId)
    }

Describe the solution to the problem

No response

Describe the uses cases for the feature

No response

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions