Ignored Error Return (ARCH5152)
هذا المحتوى غير متوفر بلغتك بعد.
Key go.logging.ignored-error-return · Severity error · Category logging
In Go, an error is a returned value. Assigning an error return to the blank identifier (_) or never checking it lets failures pass silently - the language-native analogue of a swallowed catch.
Incorrect
Section titled “Incorrect”func save(path string, data []byte) { f, _ := os.Create(path) f.Write(data) f.Close()}Correct
Section titled “Correct”func save(path string, data []byte) error { f, err := os.Create(path) if err != nil { return fmt.Errorf("create %s: %w", path, err) } defer f.Close() if _, err := f.Write(data); err != nil { return fmt.Errorf("write %s: %w", path, err) } return nil}Check every error return and propagate it wrapped to the caller; never silence it with _.