Skip to content

Commit

Permalink
keepassxc: Print error message to highlight errors which may be overseen
Browse files Browse the repository at this point in the history
  • Loading branch information
sschmid committed Oct 27, 2024
1 parent 41f8210 commit 736f864
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/plugins/keepassxc/_keepassxc_cli_with_options
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ done < <("${parse_options}" "${options}")
[[ "${command}" == "open" ]] && quiet=0
(( quiet )) && cmd_options+=("--quiet")

keepassxc-cli "${command}" "${cmd_options[@]}" "$@"
if ! keepassxc-cli "${command}" "${cmd_options[@]}" "$@"; then
echo "keepassxc-cli: Error while running the command '${command}'" >&2
exit 1
fi
22 changes: 17 additions & 5 deletions test/keepassxc.bats
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,28 @@ _set_keychain() {
################################################################################

assert_item_not_exists_output() {
assert_output "Could not find entry with path $1."
cat << EOF | assert_output -
Could not find entry with path $1.
keepassxc-cli: Error while running the command '${2:-show}'
EOF
}

assert_item_already_exists_output() {
assert_output "Could not create entry with path $1."
cat << EOF | assert_output -
Could not create entry with path $1.
keepassxc-cli: Error while running the command 'add'
EOF
}

assert_removes_item_output() {
refute_output
}

assert_rm_not_found_output() {
assert_output "Entry $1 not found."
cat << EOF | assert_output -
Entry $1 not found.
keepassxc-cli: Error while running the command 'rm'
EOF
}

assert_username() {
Expand Down Expand Up @@ -328,7 +337,7 @@ ${KEYCHAIN_TEST_PASSWORD}
${PW_2}
EOF
assert_failure
assert_item_not_exists_output "${NAME_A}"
assert_item_not_exists_output "${NAME_A}" "edit"
}

################################################################################
Expand Down Expand Up @@ -375,7 +384,10 @@ EOF
assert_adds_item_with_keychain_password "${PW_1}" "${NAME_A}" "${ACCOUNT_A}"
run pw ls <<< "wrong"
assert_failure
assert_output "Error while reading the database ${PW_KEYCHAIN}: Invalid credentials were provided, please try again."
cat << EOF | assert_output -
keepassxc-cli: Error while running the command 'ls'
Error while reading the database ${PW_KEYCHAIN}: Invalid credentials were provided, please try again.
EOF
}

@test "lists sorted items with key-file" {
Expand Down

0 comments on commit 736f864

Please sign in to comment.