Go

Go

Made by DeepSource

Empty error string GO-W1024

Bug risk
Major

Often, empty error strings (errors.New("") or fmt.Errorf("")) are present in the codebase so that they can be later replaced with appropriate errors, but they sometimes might get missed. We recommend checking the empty error strings in your codebase to see if they are intentional or need to be replaced with appropriate errors.

Bad practice

func doWork(n int) error {
    if n < 0 {
        return errors.New("")
    }
    return nil
}

Recommended

func doWork(n int) error {
    if n < 0 {
        return errors.New("n is less than 0")
    }
    return nil
}