suborbital / subo

The Suborbital CLI
Apache License 2.0
81 stars 24 forks source link

Missing error assignment leads to missed error checking #185

Closed javorszky closed 2 years ago

javorszky commented 2 years ago

Here: https://github.com/suborbital/subo/blob/main/builder/template/config.go#L38

    config, err := os.UserConfigDir()
    if err != nil {
        return "", errors.Wrap(err, "failed to get UserConfigDir")
    }

    tmplPath := filepath.Join(config, "suborbital", "templates")

    if os.Stat(tmplPath); err != nil {
        //
    }

The err != nil check after os.Stat is using the err variable from or.UserConfigDir, and we already guaranteed that's always going to be nil by the time execution gets to os.Stat.

Should be

if err := os.Stat(tmplPath); err != nil {