Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling capitalize() on undefined returns an unhelpful error message #253

Open
MichalBryxi opened this issue Jun 19, 2021 · 1 comment
Open

Comments

@MichalBryxi
Copy link

The problem

When calling capitalize() on undefined:

import { capitalize } from '@ember/string';

return capitalize(undefined);

One will get a weird error:

Uncaught TypeError: Cannot read property 'replace' of undefined
    at Cache.func (ember.debug.js:41546)
    at Cache.get (ember.debug.js:30881)
    at Object.capitalize (ember.debug.js:41770)
    at ApplicationController.get foo [as foo] (about:srcdoc:35)
    at getPossibleMandatoryProxyValue (ember.debug.js:14419)
    at get (ember.debug.js:14485)
    at ember.debug.js:46909
    at runInAutotrackingTransaction (ember.debug.js:54899)
    at track (ember.debug.js:55486)
    at PropertyReference.value (ember.debug.js:46908)
@MichalBryxi
Copy link
Author

Possible solutions:

a) Accept undefined and return empty string. I like that this makes sure that invalid input does not make the consuming app explode, but is that really what should happen? Doesn't that introduce potential bugs into users code?
b) assert() a warning saying that "capitalize helper can't accept undefined as an argument" or something.

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

No branches or pull requests

1 participant