Commit 250412b0 authored by Sebastian Stark's avatar Sebastian Stark

schedules.addFromFile() should return an error

parent 5c06fce1
......@@ -177,7 +177,10 @@ func loadConfig() (*Config, error) {
return nil, err
}
if config.SchedFile != "" {
schedules.addFromFile(config.SchedFile)
err := schedules.addFromFile(config.SchedFile)
if err != nil {
return nil, err
}
}
if _, ok := schedules[config.Schedule]; ok == false {
return nil, fmt.Errorf("no such schedule: %s\n", config.Schedule)
......@@ -223,7 +226,10 @@ func loadConfig() (*Config, error) {
return nil, err
}
if config.SchedFile != "" {
schedules.addFromFile(config.SchedFile)
err := schedules.addFromFile(config.SchedFile)
if err != nil {
return nil, err
}
}
err := config.ReadCache()
if err != nil {
......
......@@ -64,30 +64,24 @@ var schedules = scheduleList{
}
// addFromFile adds an external JSON file to the list of available scheds
func (schl scheduleList) addFromFile(file string) {
func (schl scheduleList) addFromFile(file string) error {
// If we are using the default file name, and it doesn't exist, no problem, just return
if _, err := os.Stat(file); os.IsNotExist(err) && file == defaultSchedFileName {
return
return nil
}
schedFile, err := ioutil.ReadFile(file)
if err != nil {
fmt.Printf("Error opening schedule file: %v\n", err)
return
return fmt.Errorf("Error opening schedule file: %v", err)
}
var readData map[string]jsonInterval
err = json.Unmarshal(schedFile, &readData)
if err != nil {
fmt.Printf("Error parsing data: %v\n", err)
return
return fmt.Errorf("Error parsing schedule file: %v", err)
}
for k, v := range readData {
schl[k] = v.intervalList()
}
return nil
}
// list prints the stored schedules in the list
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment