OneBug This week's bugs
Spot the bug Go
1
package main
2
 
3
import "fmt"
4
 
5
var files = map[string]string{"prod.cfg": "port=9090"}
6
 
7
// Load the config, falling back to the default when no path is set.
8
func loadConfig(path string) (string, error) {
9
	cfg := "port=8080"
10
	if path != "" {
11
		cfg, ok := files[path]
12
		if !ok {
13
			return cfg, fmt.Errorf("missing %s", path)
14
		}
15
	}
16
	return cfg, nil
17
}
18
 
19
func main() {
20
	fmt.Println(loadConfig("prod.cfg"))
21
	// expected: port=9090 <nil>, actual: port=8080 <nil>  (!)
22
}

Read the full write-up for this bug (spoilers)