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

🐛 Add missing non JSON ask error handling #1609

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

sadlowskij
Copy link
Contributor

Proposed Changes

Provoking an error in alexa ask deployment sometimes results in an error in the getAskError function.

Example:
Using a non existent ask profile like so:

new AlexaCli({askProfile: 'does-not-exist', locales: {en: ['en-US']}})

This leads to the stderr:

Command failed: ask smapi create-upload-url -p does-not-exist
Debugger listening on ws://127.0.0.1:42595/25792652-dbcc-412d-bf9d-4db5fcbd8620
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Debugger listening on ws://127.0.0.1:39601/8953403c-efec-4e66-a3c0-89661f15f337
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
[Error]: Can't resolve profile [does-not-exist] as it doesn't exist. Please run "ask configure --profile does-not-exist" first.

The current version of getAskError tries to parse the substring after [Error], in this case this text Can't resolve profile [does-not-exist] as it doesn't exist. Please run "ask configure --profile does-not-exist" first.. As this clearly is no JSON object/array. This JSON.parse throws an error resulting in this being displayed after running jovo deploy:platform alexa:

🚀 Deploying Alexa Skill
  ✖ Uploading skill package
                                                                                
x Error: --------------------------------------------------------------------------------
›                                                                                 
› Message:
›  Unexpected token C in JSON at position 0
›                                                                                 
› Module:
›  JovoCliCore
›                                                                                 
›                                                                                 
› If you think this is not on you, you can submit an issue here: https://github.com/jovotech/jovo-cli/issues.

This is why I built a block to catch the error from JSON.parse, which creates the JovoCliError in a different way, leading to the actual helpful error message being displayed after running the jovo deploy, in this case:

🚀 Deploying Alexa Skill
  ✖ Uploading skill package
                                                                                
x Error: --------------------------------------------------------------------------------
›                                                                                 
› Message:
›  smapiCreateUploadUrl: Can't resolve profile [does-not-exist] as it doesn't exist. Please run "ask configure --profile does-not-exist" first.
›  
›                                                                                 
› Module:
›  AlexaCli
›                                                                                 
›                                                                                 
› If you think this is not on you, you can submit an issue here: https://github.com/jovotech/jovo-cli/issues.

As this further increased the size of the function I also refactored some logic into its own function getViolation to improve readability.

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

@aswetlow
Copy link
Member

Thank you, Joshua!

Copy link
Member

@jankoenig jankoenig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you @sadlowskij!

@jankoenig jankoenig merged commit 3f6ea61 into jovotech:v4/dev Jan 18, 2024
6 checks passed
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

Successfully merging this pull request may close these issues.

3 participants