Skip to content

NonEmpty has a non-failable initializer. #71

@joeshonm

Description

@joeshonm

I'm working with this library and noticed that there are scenarios where a runtime error/crash can occur if an empty string is passed to the NonEmpty or NonEmptyString initializer. This all depends on the type of initialization used. Below I have examples.

Failable Initializer (You can guard against this)

NonEmptyString(rawValue: "")

Non-Failable Initializer (This will crash the app)

NonEmptyString("")

Non-Failable with Functions (This will crash the app)

func someFunc(label: NonEmptyString) {
    print(label.rawValue)
}

someFunc("")

The second option seems like the obvious choice when developing, but does not have the desired outcome.

The first option allows us to guard against a NonEmptyString and does not crash the application. The second option will cause a crash as the initializer is non-failable.

The third example shows how the application can crash when using NonEmptyString for a functions value Type.

I would like to know the purpose of both options or should this be updated so both options are failable?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions