mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-07-26 09:58:40 +00:00
cleanup some error handling lint issues
This commit is contained in:
@@ -127,6 +127,9 @@ func readConfig(configPath string) (config.Config, error) {
|
||||
}
|
||||
|
||||
validatedConfigBytes, err := json.Marshal(yamlMap)
|
||||
if err != nil {
|
||||
return config.Config{}, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(validatedConfigBytes, &cfg)
|
||||
if err != nil {
|
||||
|
||||
+5
-2
@@ -58,7 +58,10 @@ func (as *ApiServer) Start(config config.ApiConfig) {
|
||||
}
|
||||
|
||||
go func() {
|
||||
as.server.ListenAndServe()
|
||||
err := as.server.ListenAndServe()
|
||||
if err != nil && err != http.ErrServerClosed {
|
||||
as.logger.Error("server error", "error", err)
|
||||
}
|
||||
as.shutdown()
|
||||
}()
|
||||
}
|
||||
@@ -148,7 +151,7 @@ func (as *ApiServer) handleConfigHTTP(w http.ResponseWriter, req *http.Request)
|
||||
http.Error(w, "Bad request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
err, moduleErrors, routeErrors := as.configurableRouter.UpdateConfig(newConfig, true)
|
||||
moduleErrors, routeErrors, err := as.configurableRouter.UpdateConfig(newConfig, true)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusConflict)
|
||||
return
|
||||
|
||||
@@ -35,6 +35,11 @@ func (mccc *MIDIControlChangeCreate) Process(ctx context.Context, wrappedPayload
|
||||
|
||||
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, err
|
||||
}
|
||||
|
||||
var controlBuffer bytes.Buffer
|
||||
err = mccc.Control.Execute(&controlBuffer, templateData)
|
||||
|
||||
@@ -45,6 +50,11 @@ func (mccc *MIDIControlChangeCreate) Process(ctx context.Context, wrappedPayload
|
||||
|
||||
controlValue, err := strconv.ParseUint(controlBuffer.String(), 10, 8)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, err
|
||||
}
|
||||
|
||||
var valueBuffer bytes.Buffer
|
||||
err = mccc.Value.Execute(&valueBuffer, templateData)
|
||||
|
||||
@@ -55,6 +65,11 @@ func (mccc *MIDIControlChangeCreate) Process(ctx context.Context, wrappedPayload
|
||||
|
||||
valueValue, err := strconv.ParseUint(valueBuffer.String(), 10, 8)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, err
|
||||
}
|
||||
|
||||
payloadMessage := midi.ControlChange(uint8(channelValue), uint8(controlValue), uint8(valueValue))
|
||||
wrappedPayload.Payload = payloadMessage
|
||||
return wrappedPayload, nil
|
||||
|
||||
@@ -35,6 +35,11 @@ func (mnoc *MIDINoteOffCreate) Process(ctx context.Context, wrappedPayload commo
|
||||
|
||||
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, err
|
||||
}
|
||||
|
||||
var noteBuffer bytes.Buffer
|
||||
err = mnoc.Note.Execute(¬eBuffer, templateData)
|
||||
|
||||
@@ -45,6 +50,11 @@ func (mnoc *MIDINoteOffCreate) Process(ctx context.Context, wrappedPayload commo
|
||||
|
||||
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, err
|
||||
}
|
||||
|
||||
var velocityBuffer bytes.Buffer
|
||||
err = mnoc.Velocity.Execute(&velocityBuffer, templateData)
|
||||
|
||||
@@ -54,6 +64,12 @@ func (mnoc *MIDINoteOffCreate) Process(ctx context.Context, wrappedPayload commo
|
||||
}
|
||||
|
||||
velocityValue, err := strconv.ParseUint(velocityBuffer.String(), 10, 8)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, err
|
||||
}
|
||||
|
||||
payloadMessage := midi.NoteOffVelocity(uint8(channelValue), uint8(noteValue), uint8(velocityValue))
|
||||
wrappedPayload.Payload = payloadMessage
|
||||
return wrappedPayload, nil
|
||||
|
||||
@@ -35,6 +35,11 @@ func (mnoc *MIDINoteOnCreate) Process(ctx context.Context, wrappedPayload common
|
||||
|
||||
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, err
|
||||
}
|
||||
|
||||
var noteBuffer bytes.Buffer
|
||||
err = mnoc.Note.Execute(¬eBuffer, templateData)
|
||||
|
||||
@@ -45,6 +50,11 @@ func (mnoc *MIDINoteOnCreate) Process(ctx context.Context, wrappedPayload common
|
||||
|
||||
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, err
|
||||
}
|
||||
|
||||
var velocityBuffer bytes.Buffer
|
||||
err = mnoc.Velocity.Execute(&velocityBuffer, templateData)
|
||||
|
||||
@@ -54,6 +64,11 @@ func (mnoc *MIDINoteOnCreate) Process(ctx context.Context, wrappedPayload common
|
||||
}
|
||||
|
||||
velocityValue, err := strconv.ParseUint(velocityBuffer.String(), 10, 8)
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, err
|
||||
}
|
||||
|
||||
payloadMessage := midi.NoteOn(uint8(channelValue), uint8(noteValue), uint8(velocityValue))
|
||||
wrappedPayload.Payload = payloadMessage
|
||||
return wrappedPayload, nil
|
||||
|
||||
@@ -34,6 +34,11 @@ func (mpcc *MIDIProgramChangeCreate) Process(ctx context.Context, wrappedPayload
|
||||
|
||||
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, err
|
||||
}
|
||||
|
||||
var programBuffer bytes.Buffer
|
||||
err = mpcc.Program.Execute(&programBuffer, templateData)
|
||||
|
||||
@@ -44,6 +49,11 @@ func (mpcc *MIDIProgramChangeCreate) Process(ctx context.Context, wrappedPayload
|
||||
|
||||
programValue, err := strconv.ParseUint(programBuffer.String(), 10, 8)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, err
|
||||
}
|
||||
|
||||
payloadMessage := midi.ProgramChange(uint8(channelValue), uint8(programValue))
|
||||
wrappedPayload.Payload = payloadMessage
|
||||
return wrappedPayload, nil
|
||||
|
||||
@@ -32,9 +32,13 @@ func (sj *ScriptJS) Process(ctx context.Context, wrappedPayload common.WrappedPa
|
||||
}
|
||||
}
|
||||
|
||||
sj.vm.SetProperty(sj.vm.GlobalObject(), sj.payloadAtom, wrappedPayload.Payload)
|
||||
err := sj.vm.SetProperty(sj.vm.GlobalObject(), sj.payloadAtom, wrappedPayload.Payload)
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, err
|
||||
}
|
||||
|
||||
_, err := sj.vm.Eval(sj.Program, quickjs.EvalGlobal)
|
||||
_, err = sj.vm.Eval(sj.Program, quickjs.EvalGlobal)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
|
||||
@@ -209,6 +209,13 @@ func TestBadScriptJS(t *testing.T) {
|
||||
Params: test.params,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if test.errorString != err.Error() {
|
||||
t.Fatalf("script.js got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
|
||||
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user