Skip to content

Commit

Permalink
fine tune error message
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed May 7, 2023
1 parent a99e830 commit dc96bec
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion modules/secret/secret.go
Expand Up @@ -73,7 +73,7 @@ func DecryptSecret(key, cipherHex string) (string, error) {
}
plaintext, err := AesDecrypt(keyHash[:], ciphertext)
if err != nil {
return "", fmt.Errorf("failed to decrypt by secret, secret key (SECRET_KEY) might be incorrect: %w", err)
return "", fmt.Errorf("failed to decrypt by secret, the key (maybe SECRET_KEY?) might be incorrect: %w", err)
}
return string(plaintext), nil
}
4 changes: 2 additions & 2 deletions modules/secret/secret_test.go
Expand Up @@ -24,8 +24,8 @@ func TestEncryptDecrypt(t *testing.T) {
assert.ErrorContains(t, err, "invalid hex string")

_, err = DecryptSecret("a", "bb")
assert.ErrorContains(t, err, "secret key (SECRET_KEY) might be incorrect: AesDecrypt ciphertext too short")
assert.ErrorContains(t, err, "the key (maybe SECRET_KEY?) might be incorrect: AesDecrypt ciphertext too short")

_, err = DecryptSecret("a", "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
assert.ErrorContains(t, err, "secret key (SECRET_KEY) might be incorrect: AesDecrypt invalid decrtyped base64 string")
assert.ErrorContains(t, err, "the key (maybe SECRET_KEY?) might be incorrect: AesDecrypt invalid decrypted base64 string")
}

0 comments on commit dc96bec

Please sign in to comment.