From 7487402fb90a3411b23749d489f58f22b24499f6 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Tue, 11 Nov 2025 10:44:40 +0800 Subject: style(info.go): handle error internally --- info.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/info.go b/info.go index 17b6b13..cfc80f0 100644 --- a/info.go +++ b/info.go @@ -5,6 +5,7 @@ import ( "os/exec" "strings" "bytes" + "github.com/fatih/color" ) type FormulaInfo struct { @@ -36,10 +37,11 @@ type CaskInfo struct { // GetInfo fetches package info for both formulae and casks. // It returns one of the two structs depending on the package type. -func GetInfo(pkg string) (*FormulaInfo, *CaskInfo, error) { +func GetInfo(pkg string) (*FormulaInfo, *CaskInfo) { out, err := exec.Command("brew", "info", "--json=v2", pkg).Output() if err != nil { - return nil, nil, err + color.Red("❌ Error fetching info. Please check for typo.") + return nil, nil } var data struct { @@ -48,17 +50,18 @@ func GetInfo(pkg string) (*FormulaInfo, *CaskInfo, error) { } if err := json.Unmarshal(out, &data); err != nil { - return nil, nil, err + color.Red("❌ Error parsing data.") + return nil, nil } if len(data.Formulae) > 0 { - return &data.Formulae[0], nil, nil + return &data.Formulae[0], nil } if len(data.Casks) > 0 { - return nil, &data.Casks[0], nil + return nil, &data.Casks[0] } - return nil, nil, nil // not found + return nil, nil // not found } func GetReverseDependencies(pkg string) ([]string, error) { -- cgit v1.2.3