From 08a5a7c6d50bf5830439d554516c69e801cfbf18 Mon Sep 17 00:00:00 2001 From: Johnny Santamaria Date: Tue, 1 Apr 2025 13:10:46 -0700 Subject: [PATCH] Fix crash when resizing terminal buffer in server selection menu Fixes #8 Add error handling to the `resize` method in `lib/eclair/grid.rb` to gracefully handle terminal buffer size changes. * Wrap the existing `resize` method code in a `begin-rescue` block to catch and handle exceptions. * Add a `log_error` method to log any errors encountered during the resize process to an "error.log" file. --- lib/eclair/grid.rb | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/eclair/grid.rb b/lib/eclair/grid.rb index 23e9b13..afd655c 100644 --- a/lib/eclair/grid.rb +++ b/lib/eclair/grid.rb @@ -119,12 +119,23 @@ def action end def resize - Curses.clear - @scroll.fill(0) - @cell_width = Curses.stdscr.maxx/config.columns - @maxy = Curses.stdscr.maxy - @header_rows - rescroll(*@cursor) - draw_all + begin + Curses.clear + @scroll.fill(0) + @cell_width = Curses.stdscr.maxx/config.columns + @maxy = Curses.stdscr.maxy - @header_rows + rescroll(*@cursor) + draw_all + rescue => e + log_error(e) + end + end + + def log_error(error) + File.open("error.log", "a") do |file| + file.puts("#{Time.now}: #{error.message}") + file.puts(error.backtrace) + end end def transit_mode to