Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use errors.New to replace fmt.Errorf with no parameters will much better #986

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions examples/credit-card-form/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"log"
"strconv"
Expand Down Expand Up @@ -50,17 +51,17 @@ func ccnValidator(s string) error {
// Credit Card Number should a string less than 20 digits
// It should include 16 integers and 3 spaces
if len(s) > 16+3 {
return fmt.Errorf("CCN is too long")
return errors.New("CCN is too long")
}

if len(s) == 0 || len(s)%5 != 0 && (s[len(s)-1] < '0' || s[len(s)-1] > '9') {
return fmt.Errorf("CCN is invalid")
return errors.New("CCN is invalid")
}

// The last digit should be a number unless it is a multiple of 4 in which
// case it should be a space
if len(s)%5 == 0 && s[len(s)-1] != ' ' {
return fmt.Errorf("CCN must separate groups with spaces")
return errors.New("CCN must separate groups with spaces")
}

// The remaining digits should be integers
Expand All @@ -76,12 +77,12 @@ func expValidator(s string) error {
e := strings.ReplaceAll(s, "/", "")
_, err := strconv.ParseInt(e, 10, 64)
if err != nil {
return fmt.Errorf("EXP is invalid")
return errors.New("EXP is invalid")
}

// There should be only one slash and it should be in the 2nd index (3rd character)
if len(s) >= 3 && (strings.Index(s, "/") != 2 || strings.LastIndex(s, "/") != 2) {
return fmt.Errorf("EXP is invalid")
return errors.New("EXP is invalid")
}

return nil
Expand Down
7 changes: 4 additions & 3 deletions inputreader_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package tea

import (
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -129,11 +130,11 @@ func waitForInput(conin, cancel windows.Handle) error {

return fmt.Errorf("unexpected wait object is ready: %d", event-windows.WAIT_OBJECT_0)
case windows.WAIT_ABANDONED <= event && event < windows.WAIT_ABANDONED+2:
return fmt.Errorf("abandoned")
return errors.New("abandoned")
case event == uint32(windows.WAIT_TIMEOUT):
return fmt.Errorf("timeout")
return errors.New("timeout")
case event == windows.WAIT_FAILED:
return fmt.Errorf("failed")
return errors.New("failed")
default:
return fmt.Errorf("unexpected error: %w", err)
}
Expand Down