From c887f2a0ccf1e8fc56e18db68774341ece3cb0a1 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Thu, 24 Apr 2025 22:29:28 -0400 Subject: [PATCH] Don't panic; throw error instead --- color.go | 2 +- main.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/color.go b/color.go index 189fe20..0c54650 100644 --- a/color.go +++ b/color.go @@ -157,7 +157,7 @@ func stringToRGB(rgbString string) (*RGB, error) { func loadColorsFromFile(filepath string) error { data, err := os.ReadFile(filepath) if err != nil { - panic(err) + return err } // Read color config file into a MapSlice tempMapSlice := yaml.MapSlice{} diff --git a/main.go b/main.go index 5d5cad9..993026c 100644 --- a/main.go +++ b/main.go @@ -79,7 +79,7 @@ func main() { // Check if config exists. If it doesn't, generate the config files. userHomeDir, err := os.UserHomeDir() // Get current user's home directory, to construct config path if err != nil { - panic(err) + printErrAndExit("Unable to retrieve user home directory") } configPath := filepath.Join(userHomeDir + "/.config/ccat/") if _, err := os.Stat(configPath); os.IsNotExist(err) { @@ -107,7 +107,7 @@ func main() { // the program. finfo, err := os.Stat(fileName) if err != nil { - panic(err) + printErrAndExit("Unable to read file") } if finfo.Size() == 0 { os.Exit(0)