Skip to content

Commit

Permalink
perf(errno): Cache capitalized error description
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Oct 10, 2024
1 parent b51a975 commit 813b5ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 2 additions & 4 deletions cmd/errno/run_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func run(cmd *cobra.Command, args []string) error {
if util.Must2(cmd.Flags().GetBool(FlagSearch)) {
search := strings.ToLower(strings.Join(args, " "))
for e := range errno.Iter() {
if strings.Contains(e.Error(), search) {
if strings.Contains(strings.ToLower(e.Error()), search) {
if err := printErrno(cmd, e); err != nil {
return err
}
Expand Down Expand Up @@ -71,8 +71,6 @@ func findErrno(cmd *cobra.Command, arg string) error {
}

func printErrno(cmd *cobra.Command, e *errno.Errno) error {
pretty := e.Error()
pretty = strings.ToUpper(pretty[0:1]) + pretty[1:]
_, err := fmt.Fprintf(cmd.OutOrStdout(), "%s %d %s\n", e.Name(), uint(e.Errno), pretty)
_, err := fmt.Fprintf(cmd.OutOrStdout(), "%s %d %s\n", e.Name(), uint(e.Errno), e.Error())
return err
}
4 changes: 4 additions & 0 deletions internal/errno/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package errno

import (
"strings"
"syscall"

"golang.org/x/exp/constraints"
Expand Down Expand Up @@ -50,6 +51,9 @@ func (e *Errno) Name() string {
func (e *Errno) Error() string {
if e.desc == "" {
e.desc = e.Errno.Error()
if len(e.desc) >= 2 {
e.desc = strings.ToUpper(e.desc[0:1]) + e.desc[1:]
}
}
return e.desc
}

0 comments on commit 813b5ba

Please sign in to comment.