From a4f1f49fab6665526c9bea747c610bdc8c5e859f Mon Sep 17 00:00:00 2001 From: Tw93 Date: Fri, 23 Jan 2026 22:25:35 +0800 Subject: [PATCH] feat: improve version detection and error handling - Add fallback to mo --version when brew list fails - Add error handling for debug log write failures - Improve version extraction with multiple fallback strategies --- lib/core/common.sh | 2 ++ lib/core/log.sh | 4 +++- mole | 8 +++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/core/common.sh b/lib/core/common.sh index 21a427e..75da002 100755 --- a/lib/core/common.sh +++ b/lib/core/common.sh @@ -79,6 +79,7 @@ update_via_homebrew() { if echo "$upgrade_output" | grep -q "already installed"; then local installed_version installed_version=$(brew list --versions mole 2> /dev/null | awk '{print $2}') + [[ -z "$installed_version" ]] && installed_version=$(mo --version 2> /dev/null | awk '/Mole version/ {print $3; exit}') echo "" echo -e "${GREEN}${ICON_SUCCESS}${NC} Already on latest version (${installed_version:-$current_version})" echo "" @@ -90,6 +91,7 @@ update_via_homebrew() { echo "$upgrade_output" | grep -Ev "^(==>|Updating Homebrew|Warning:)" || true local new_version new_version=$(brew list --versions mole 2> /dev/null | awk '{print $2}') + [[ -z "$new_version" ]] && new_version=$(mo --version 2> /dev/null | awk '/Mole version/ {print $3; exit}') echo "" echo -e "${GREEN}${ICON_SUCCESS}${NC} Updated to latest version (${new_version:-$current_version})" echo "" diff --git a/lib/core/log.sh b/lib/core/log.sh index d9dca13..124ee7b 100644 --- a/lib/core/log.sh +++ b/lib/core/log.sh @@ -180,7 +180,9 @@ log_system_info() { # Reset debug log file for this new session ensure_user_file "$DEBUG_LOG_FILE" - : > "$DEBUG_LOG_FILE" + if ! : > "$DEBUG_LOG_FILE" 2> /dev/null; then + echo -e "${YELLOW}${ICON_WARNING}${NC} Debug log not writable: $DEBUG_LOG_FILE" >&2 + fi # Start block in debug log file { diff --git a/mole b/mole index 4f3c1b6..ff365d3 100755 --- a/mole +++ b/mole @@ -346,7 +346,13 @@ update_mole() { if ! printf '%s\n' "$output" | grep -Eq "Updated to latest version|Already on latest version"; then local new_version - new_version=$("$mole_path" --version 2> /dev/null | awk 'NR==1 && NF {print $NF}' || echo "") + new_version=$(printf '%s\n' "$output" | sed -n 's/.*(\([^)]*\)).*/\1/p' | head -1) + if [[ -z "$new_version" ]]; then + new_version=$("$mole_path" --version 2> /dev/null | awk 'NR==1 && NF {print $NF}' || echo "") + fi + if [[ -z "$new_version" ]]; then + new_version="$latest" + fi printf '\n%s\n\n' "${GREEN}${ICON_SUCCESS}${NC} Updated to latest version (${new_version:-unknown})" else printf '\n'