From 66cc8f7696d83a7158be873e45331e3bbc2edd9e Mon Sep 17 00:00:00 2001 From: "shengwei.psw" Date: Thu, 12 Mar 2026 19:52:50 +0800 Subject: [PATCH] fix: improve error handling and add config backup Address additional review feedback: - Guard default plugin path resolution with friendly error message suggesting explicit path when cli-anything-plugin dir not found - Create backup of existing ~/.qoder.json before modification to allow easy revert if update is undesired Co-Authored-By: Claude Opus 4.6 --- qoder-plugin/setup-qodercli.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/qoder-plugin/setup-qodercli.sh b/qoder-plugin/setup-qodercli.sh index 71ef425ac..e92ec77d2 100755 --- a/qoder-plugin/setup-qodercli.sh +++ b/qoder-plugin/setup-qodercli.sh @@ -23,7 +23,12 @@ if [ $# -ge 1 ]; then fi else # Default to cli-anything-plugin relative to qoder-plugin directory - PLUGIN_DIR="$(cd "${SCRIPT_DIR}/../cli-anything-plugin" && pwd)" + if ! PLUGIN_DIR="$(cd "${SCRIPT_DIR}/../cli-anything-plugin" 2>/dev/null && pwd)"; then + echo -e "${YELLOW}Error: Could not find cli-anything-plugin directory at ${SCRIPT_DIR}/../cli-anything-plugin${NC}" >&2 + echo -e "${YELLOW}Please provide an explicit plugin path:${NC}" >&2 + echo -e "${YELLOW} bash setup-qodercli.sh /path/to/cli-anything-plugin${NC}" >&2 + exit 1 + fi fi # Validate plugin directory @@ -90,6 +95,9 @@ if [ -f "${QODER_CONFIG}" ]; then echo -e "${GREEN}✓ Plugin already registered in ${QODER_CONFIG}${NC}" else # Add plugin to existing config + # Backup original config before modification + cp "${QODER_CONFIG}" "${QODER_CONFIG}.bak" + echo -e " Backup saved to ${QODER_CONFIG}.bak" # Create temp file in same directory for atomic mv on same filesystem TMP_CONFIG=$(mktemp "${CONFIG_DIR}/.qoder.json.XXXXXX") jq --arg path "${PLUGIN_DIR}" '