-
Notifications
You must be signed in to change notification settings - Fork 22
Fix Cannot read properties of null (reading 'toLowerCase') #292
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a null reference error where state.val could be null when calling toLowerCase() method. The fix adds proper null checking and input validation for the favorites_set state handler.
- Added null safety by converting
state.valto string with fallback to empty string - Added validation to skip processing when no valid favorite name is provided
- Replaced direct
state.valusage with the sanitizedfavvariable
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if (!fav) { | ||
| adapter.log.warn('favorites_set called without valid favorite name – skipped'); | ||
| } else { | ||
| promise = player | ||
| .replaceWithFavorite(fav) | ||
| .then(() => player.play()) | ||
| .then(() => { | ||
| adapter.setState( | ||
| { device: 'root', channel: id.channel, state: 'current_album' }, | ||
| { val: fav, ack: true } | ||
| ); | ||
| adapter.setState( | ||
| { | ||
| device: 'root', | ||
| channel: id.channel, | ||
| state: 'current_artist' | ||
| }, | ||
| { val: fav, ack: true } | ||
| ); | ||
| }) | ||
| .catch(error => adapter.log.error(`Cannot replaceWithFavorite: ${error}`)); | ||
| } |
Copilot
AI
Oct 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation: this line uses tabs while the surrounding code uses spaces. Should use spaces to match the existing code style.
| if (!fav) { | ||
| adapter.log.warn('favorites_set called without valid favorite name – skipped'); | ||
| } else { | ||
| promise = player | ||
| .replaceWithFavorite(fav) | ||
| .then(() => player.play()) | ||
| .then(() => { | ||
| adapter.setState( | ||
| { device: 'root', channel: id.channel, state: 'current_album' }, | ||
| { val: fav, ack: true } | ||
| ); | ||
| adapter.setState( | ||
| { | ||
| device: 'root', | ||
| channel: id.channel, | ||
| state: 'current_artist' | ||
| }, | ||
| { val: fav, ack: true } | ||
| ); | ||
| }) | ||
| .catch(error => adapter.log.error(`Cannot replaceWithFavorite: ${error}`)); | ||
| } |
Copilot
AI
Oct 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation: these lines use tabs while the surrounding code uses spaces. Should use spaces to match the existing code style.
| if (!fav) { | ||
| adapter.log.warn('favorites_set called without valid favorite name – skipped'); | ||
| } else { | ||
| promise = player | ||
| .replaceWithFavorite(fav) | ||
| .then(() => player.play()) | ||
| .then(() => { | ||
| adapter.setState( | ||
| { device: 'root', channel: id.channel, state: 'current_album' }, | ||
| { val: fav, ack: true } | ||
| ); | ||
| adapter.setState( | ||
| { | ||
| device: 'root', | ||
| channel: id.channel, | ||
| state: 'current_artist' | ||
| }, | ||
| { val: fav, ack: true } | ||
| ); | ||
| }) | ||
| .catch(error => adapter.log.error(`Cannot replaceWithFavorite: ${error}`)); |
Copilot
AI
Oct 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation: this line uses tabs while the surrounding code uses spaces. Should use spaces to match the existing code style.
| ); | ||
| }) | ||
| .catch(error => adapter.log.error(`Cannot replaceWithFavorite: ${error}`)); | ||
| } |
Copilot
AI
Oct 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation: this line uses tabs while the surrounding code uses spaces. Should use spaces to match the existing code style.
| } | |
| } |
No description provided.