Go

Go

By DeepSource

Empty error string GO-W1024

Bug risk

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.

Examples

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
}