diff options
| author | Eltrac <hi@guhub.cn> | 2025-11-11 10:44:40 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-11-11 10:44:40 +0800 |
| commit | 7487402fb90a3411b23749d489f58f22b24499f6 (patch) | |
| tree | 9f71a513bf09af5cd5d9e4460b85fba5665d9e12 | |
| parent | 01785b30016779e46d90febc421e22a3d7e32b9e (diff) | |
style(info.go): handle error internally
| -rw-r--r-- | info.go | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -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) { |
