-
Notifications
You must be signed in to change notification settings - Fork 43
Description
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?