Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

$cacheFactory.remove() throws exception when the key does not exists #1497

Closed
mlegenhausen opened this issue Oct 25, 2012 · 4 comments
Closed
Labels

Comments

@mlegenhausen
Copy link

Instead it should simply return.

TypeError: Cannot read property 'n' of undefined
    at Object.caches.(anonymous function).remove (http://localhost:8080/js/lib/angular/angular.js:3318:24)

Angular Version 1.0.2

@pkozlowski-opensource
Copy link
Member

Reproduce scenario: http://jsfiddle.net/MC3wm/ (error in the console).

It is probably a good idea to ignore removal of non-existing values (that is, don't throw exceptions in this case). Or at least provide a more descriptive error message.

@jtymes
Copy link
Contributor

jtymes commented Nov 13, 2012

@pkozlowski-opensource I saw your comment come through my email but it seems to have disappeared. After you mentioned it, I did a few tests with putting in 0 or false in the cache but it seemed to work alright. I can change it over to use isUndefined() instead if you think that would be a safer route.

@pkozlowski-opensource
Copy link
Member

@jtymes Ignore my comment, I've misread your code. The fix looks good. Travis-CI is failing atm but I'm not sure if this is linked to your fix.

@mlegenhausen
Copy link
Author

Looks good, cause there the only results of var lruEntry = lruHash[key]; can be an object or undefined. Where the first case will be always true and the seconds always false.

IgorMinar pushed a commit that referenced this issue Nov 24, 2012
Instead of throwning an exception, remove should return undefined when
cache entry to be removed doesn't exist.

Closes #1497
IgorMinar pushed a commit to IgorMinar/angular.js that referenced this issue Nov 26, 2012
Instead of throwning an exception, remove should return undefined when
cache entry to be removed doesn't exist.

Closes angular#1497
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants