freeconf / restconf

Implementation of RESTCONF Management protocol - IETF RFC8040

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

local.go:ApplyStartupConfigFile function panics instead of returning an error

Kirhchoff opened this issue · comments

ApplyStartupConfigFile from local.go file currently panics when something goes wrong opening the config file (for instance when we provide an incorrect startup file path). This prevents applications from properly handling errors. It is also not in line with the function signature, which suggests it should return errors when something goes wrong

Current implementation:
https://github.com/freeconf/restconf/blob/master/device/local.go#L112

func (self *Local) ApplyStartupConfigFile(fname string) error {
	cfgRdr, err := os.Open(fname)
	defer cfgRdr.Close()
	if err != nil {
		panic(err)
	}
	return self.ApplyStartupConfig(cfgRdr)
}

I've prepared a PR for the issue #53

applied, thank you.