Skip to content

Commit

Permalink
Catch error and move it to dotenv error
Browse files Browse the repository at this point in the history
  • Loading branch information
motdotla committed Apr 7, 2023
1 parent 9d90a47 commit 13ea77f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,10 @@ function decrypt (encrypted, keyStr) {
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`
} catch (error) {
const isRange = error instanceof RangeError
const invalidKeyLength = error.message === 'Invalid key length'
const decryptionFailed = error.message === 'Unsupported state or unable to authenticate data'

if (isRange) {
if (isRange || invalidKeyLength) {
const msg = 'INVALID_DOTENV_KEY: It must be 64 characters long (or more)'
throw new Error(msg)
} else if (decryptionFailed) {
Expand Down

0 comments on commit 13ea77f

Please sign in to comment.