File operations commonly fail:
f, err := os.Open("data.txt")
if err != nil {
return fmt.Errorf("open data: %w", err)
}
defer f.Close()
data, err := io.ReadAll(f)
if err != nil {
return fmt.Errorf("read data: %w", err)
}
Each operation can fail. Check each error and add context describing what you were trying to do.