Skip to content

Fix crash on up-arrow with empty console history#44

Open
dmgerman wants to merge 1 commit intocmsj:mainfrom
dmgerman:fix/console-view-bugs
Open

Fix crash on up-arrow with empty console history#44
dmgerman wants to merge 1 commit intocmsj:mainfrom
dmgerman:fix/console-view-bugs

Conversation

@dmgerman
Copy link
Copy Markdown

@dmgerman dmgerman commented Apr 5, 2026

Summary

  • Add guard !evalHistory.isEmpty else { return .ignored } to handleUpArrow() in ConsoleView.swift
  • Without this, pressing up-arrow when no commands have been entered sets evalIndex to -1 (from count - 1 = 0 - 1) and then accesses evalHistory[-1], crashing with array index out of range

Partially addresses #43. The other two findings (unused styleForLogType, unused selectedRows) exist on the hs2 branch but not on main.

Test plan

  • Build succeeds
  • No existing unit tests for ConsoleView (SwiftUI view)
  • Manual test: launch app, open console, press up-arrow before entering any commands — should no longer crash

When evalHistory is empty, pressing up-arrow set evalIndex to -1
(count - 1 = 0 - 1) then accessed evalHistory[-1], causing an
out-of-range crash. Add an early return guard.

Fixes cmsj#43 (partially — the other two findings are on the hs2 branch).
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 5, 2026

Greptile Summary

Adds a one-line guard !evalHistory.isEmpty else { return .ignored } to handleUpArrow() in ConsoleView.swift, preventing a fatal crash. Without it, pressing up-arrow on an empty history caused evalIndex to be set to 0 - 1 = -1, and the subsequent evalHistory[-1] subscript caused a fatal index-out-of-range error. handleDownArrow() already handles the empty-history case safely via its case -1: return .ignored branch and needs no change.

Confidence Score: 5/5

Safe to merge — single targeted fix with no side effects

The change is a minimal, correct guard that addresses a confirmed crash. It only fires when evalHistory is empty, leaving all existing history-navigation behaviour untouched. handleDownArrow() is already safe for this case. No other issues found.

No files require special attention

Important Files Changed

Filename Overview
Hammerspoon 2/Windows/ConsoleView.swift Adds an empty-history guard to handleUpArrow(), correctly preventing a fatal index-out-of-range crash with no side effects on the non-empty path

Reviews (1): Last reviewed commit: "Fix crash on up-arrow with empty console..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants