-
Notifications
You must be signed in to change notification settings - Fork 11
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
fix: throw when privateDecrypt
fails for input secrets
#399
Conversation
privateDecrypt
fails for input secrets
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.
Is swallowing all errors a good idea? It can happen that changing input cannot help.
There is some known error what you can get from malformed input or decrypt key, see tests for ideas.
What about at least log the original error? Otherwise, it is very hard to debug in case of any unexpected issue.
try { | ||
decryptedInput[key] = privateDecrypt({ privateKey, encryptedPassword, encryptedValue }); | ||
} catch { | ||
throw new Error(`The input field "${key}" could not be decrypted. You can fix this by updating the field's value in the input editor.`); |
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.
Please add simple test https://github.com/apify/apify-shared-js/blob/master/test/input_secrets.test.ts#L36
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.
I added a test that expects the decrypt to throw if wrong privateKey
is provided.
try { | ||
decryptedInput[key] = privateDecrypt({ privateKey, encryptedPassword, encryptedValue }); | ||
} catch { | ||
throw new Error(`The input field "${key}" could not be decrypted. You can fix this by updating the field's value in the input editor.`); |
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.
To get around the swallowing of the original error, maybe we could add the original error as cause
to the new one, so it would be accessible?
And for the message I'd go with something like this - not saying it fixes it, just that it might, and giving some more details.
The input field "${key}" could not be decrypted. Try updating the field's value in the input editor. Decryption error: ${err}
I changed the message so now it is |
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.
👍
Comments regarding the error text message are welcome.