Error fixes:
- Add an error domain and error codes.
- Handle empty string without an assertion.
- Return an error when returning nil (per conventions).