[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => https://github.com/ngxs/store/blob/master/CONTRIBUTING.md
[ ] Other... Please describe:
When error occurs in a selector - it is swallowed and not shown in the console.
Error should be shown in the console.
@Selector()
static pandas(state: string[]) {
const foo: any = null;
console.log(foo.bar);
return state.filter(s => s.indexOf('panda') > -1);
}
Finding bugs easier in selectors.
Libs:
- @angular/core version: 7.1.4
- @ngxs/store version: 3.3.3
Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: XX
- Platform:
Others:
@ogix selectors calls are wrapped in try-catch, this decision was made in order to avoid exceptions. E.g. you've got some state that stores a null value or some object, and you want to create a selector that returns token value
@State<Token | null>({
name: 'token',
defaults: null
})
class TokenState {
@Selector()
public static getAccessToken(state: Token) {
return state.accessToken;
}
}
this won't throw and will return undefined.
@splincode what do you think?
@arturovt A console.log could be added to the catch, if developmentMode is turned on.
console.error perhaps instead when dev mode?
Isn't it possible to check if state is null before applying a selector function? And then replace try/catch with that check.
The swallowing is pretty annoying for testing, too. Most of the time I have to guess which properties I forgot to add to the initial state setup.
I think at least logging in dev mode should be added.
@ogix @sroettering You can try a new option suppressErrors.
Will be released in 3.5.0
$ npm install @ngxs/store@dev
@NgModule({
imports: [
NgxsModule.forRoot([TasksState], {
developmentMode: true,
selectorOptions: { suppressErrors: false } // default: true
})
]
})
export class AppModule {}
Thanks!
Released in 3.5.0
Most helpful comment
@ogix @sroettering You can try a new option
suppressErrors.Will be released in 3.5.0