I want to ask about best practise of error handling, Lets assume I've the following function that read file parse it, which could return two types of errors , when the file not found and the unmarshal failed
func Parse(source string) (bma.Bma, error) {
file, err := ioutil.ReadFile(source + "bma.yaml")
m := bma.Bma{}
if err != nil {
logs.Error("Not able to read the bma file")
return m, err
}
err = yaml.Unmarshal([]byte(file), &m)
if err != nil {
logs.Error("Not able to unmarshal the bma file ")
return m, err
}
return m, err
}
Now If I call to this function and there is error I printing also this error, the Program is CLI program so I think there is too much error will be printed if case of issue, Is It OK, or there is better approach ?
bma ,err := Parse("path")
if err != nil {
logs.Error("Error while parsing ")
return m, err
}