Skip to content

Commit a4f1f49

Browse files
committed
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
1 parent a27caab commit a4f1f49

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

lib/core/common.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ update_via_homebrew() {
7979
if echo "$upgrade_output" | grep -q "already installed"; then
8080
local installed_version
8181
installed_version=$(brew list --versions mole 2> /dev/null | awk '{print $2}')
82+
[[ -z "$installed_version" ]] && installed_version=$(mo --version 2> /dev/null | awk '/Mole version/ {print $3; exit}')
8283
echo ""
8384
echo -e "${GREEN}${ICON_SUCCESS}${NC} Already on latest version (${installed_version:-$current_version})"
8485
echo ""
@@ -90,6 +91,7 @@ update_via_homebrew() {
9091
echo "$upgrade_output" | grep -Ev "^(==>|Updating Homebrew|Warning:)" || true
9192
local new_version
9293
new_version=$(brew list --versions mole 2> /dev/null | awk '{print $2}')
94+
[[ -z "$new_version" ]] && new_version=$(mo --version 2> /dev/null | awk '/Mole version/ {print $3; exit}')
9395
echo ""
9496
echo -e "${GREEN}${ICON_SUCCESS}${NC} Updated to latest version (${new_version:-$current_version})"
9597
echo ""

lib/core/log.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ log_system_info() {
180180

181181
# Reset debug log file for this new session
182182
ensure_user_file "$DEBUG_LOG_FILE"
183-
: > "$DEBUG_LOG_FILE"
183+
if ! : > "$DEBUG_LOG_FILE" 2> /dev/null; then
184+
echo -e "${YELLOW}${ICON_WARNING}${NC} Debug log not writable: $DEBUG_LOG_FILE" >&2
185+
fi
184186

185187
# Start block in debug log file
186188
{

mole

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,13 @@ update_mole() {
346346

347347
if ! printf '%s\n' "$output" | grep -Eq "Updated to latest version|Already on latest version"; then
348348
local new_version
349-
new_version=$("$mole_path" --version 2> /dev/null | awk 'NR==1 && NF {print $NF}' || echo "")
349+
new_version=$(printf '%s\n' "$output" | sed -n 's/.*(\([^)]*\)).*/\1/p' | head -1)
350+
if [[ -z "$new_version" ]]; then
351+
new_version=$("$mole_path" --version 2> /dev/null | awk 'NR==1 && NF {print $NF}' || echo "")
352+
fi
353+
if [[ -z "$new_version" ]]; then
354+
new_version="$latest"
355+
fi
350356
printf '\n%s\n\n' "${GREEN}${ICON_SUCCESS}${NC} Updated to latest version (${new_version:-unknown})"
351357
else
352358
printf '\n'

0 commit comments

Comments
 (0)