Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
- Removed panics for incorrect content type in processJob.Run()
Browse files Browse the repository at this point in the history
- Now when content type is different then expected error is reported
  • Loading branch information
marcin-krolik committed Apr 18, 2016
1 parent 7ff2686 commit 497bfdf
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions scheduler/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,17 @@ func (p *processJob) Run() {
if mt, ok := m.(plugin.PluginMetricType); ok {
metrics[i] = mt
} else {
// TODO; add a log statement and return an error
// (instead of panicking)
panic("unsupported type")
log.WithFields(log.Fields{
"_module": "scheduler-job",
"block": "run",
"job-type": "processor",
"content-type": p.contentType,
"plugin-name": p.name,
"plugin-version": p.version,
"plugin-config": p.config,
"error": m,
}).Error("unsupported metric type")
p.AddErrors(fmt.Errorf("unsupported metric type. {%v}", m))
}
}
enc.Encode(metrics)
Expand All @@ -331,8 +339,6 @@ func (p *processJob) Run() {
}
p.content = content
default:
// TODO; change log from Fatal to Error and return an error
// (instead of panicking)
log.WithFields(log.Fields{
"_module": "scheduler-job",
"block": "run",
Expand All @@ -341,9 +347,10 @@ func (p *processJob) Run() {
"plugin-name": p.name,
"plugin-version": p.version,
"plugin-config": p.config,
}).Fatal("unsupported content type")
panic(fmt.Sprintf("unsupported content type. {plugin name: %s version: %v content-type: '%v'}", p.name, p.version, p.contentType))
}).Error("unsupported content type")
p.AddErrors(fmt.Errorf("unsupported content type. {plugin name: %s version: %v content-type: '%v'}", p.name, p.version, p.contentType))
}

case *processJob:
// TODO: Remove switch statement and rely on processor to catch errors in type
// (separation of concerns; remove content-type definition from the framework?)
Expand All @@ -367,8 +374,6 @@ func (p *processJob) Run() {
}
p.content = content
default:
// TODO; change log from Fatal to Error and return an error
// (instead of panicking)
log.WithFields(log.Fields{
"_module": "scheduler-job",
"block": "run",
Expand All @@ -377,12 +382,10 @@ func (p *processJob) Run() {
"plugin-name": p.name,
"plugin-version": p.version,
"plugin-config": p.config,
}).Fatal("unsupported content type")
panic(fmt.Sprintf("unsupported content type. {plugin name: %s version: %v content-type: '%v'}", p.name, p.version, p.contentType))
}).Error("unsupported content type")
p.AddErrors(fmt.Errorf("unsupported content type. {plugin name: %s version: %v content-type: '%v'}", p.name, p.version, p.contentType))
}
default:
// TODO; change log from Fatal to Error and return an error
// (instead of panicking)
log.WithFields(log.Fields{
"_module": "scheduler-job",
"block": "run",
Expand All @@ -392,8 +395,8 @@ func (p *processJob) Run() {
"plugin-version": p.version,
"plugin-config": p.config,
"parent-job-type": p.parentJob.Type(),
}).Fatal("unsupported parent job type")
panic("unsupported parent job type")
}).Error("unsupported parent job type")
p.AddErrors(fmt.Errorf("unsupported parent job type {%v}", p.parentJob.Type()))
}
}

Expand Down

0 comments on commit 497bfdf

Please sign in to comment.