mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-09-10 07:29:25 +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)
|
validatedConfigBytes, err := json.Marshal(yamlMap)
|
||||||
|
if err != nil {
|
||||||
|
return config.Config{}, err
|
||||||
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(validatedConfigBytes, &cfg)
|
err = json.Unmarshal(validatedConfigBytes, &cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+5
-2
@@ -58,7 +58,10 @@ func (as *ApiServer) Start(config config.ApiConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
as.server.ListenAndServe()
|
err := as.server.ListenAndServe()
|
||||||
|
if err != nil && err != http.ErrServerClosed {
|
||||||
|
as.logger.Error("server error", "error", err)
|
||||||
|
}
|
||||||
as.shutdown()
|
as.shutdown()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@@ -148,7 +151,7 @@ func (as *ApiServer) handleConfigHTTP(w http.ResponseWriter, req *http.Request)
|
|||||||
http.Error(w, "Bad request", http.StatusBadRequest)
|
http.Error(w, "Bad request", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err, moduleErrors, routeErrors := as.configurableRouter.UpdateConfig(newConfig, true)
|
moduleErrors, routeErrors, err := as.configurableRouter.UpdateConfig(newConfig, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusConflict)
|
http.Error(w, err.Error(), http.StatusConflict)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ func (mccc *MIDIControlChangeCreate) Process(ctx context.Context, wrappedPayload
|
|||||||
|
|
||||||
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
var controlBuffer bytes.Buffer
|
var controlBuffer bytes.Buffer
|
||||||
err = mccc.Control.Execute(&controlBuffer, templateData)
|
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)
|
controlValue, err := strconv.ParseUint(controlBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
var valueBuffer bytes.Buffer
|
var valueBuffer bytes.Buffer
|
||||||
err = mccc.Value.Execute(&valueBuffer, templateData)
|
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)
|
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))
|
payloadMessage := midi.ControlChange(uint8(channelValue), uint8(controlValue), uint8(valueValue))
|
||||||
wrappedPayload.Payload = payloadMessage
|
wrappedPayload.Payload = payloadMessage
|
||||||
return wrappedPayload, nil
|
return wrappedPayload, nil
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ func (mnoc *MIDINoteOffCreate) Process(ctx context.Context, wrappedPayload commo
|
|||||||
|
|
||||||
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
var noteBuffer bytes.Buffer
|
var noteBuffer bytes.Buffer
|
||||||
err = mnoc.Note.Execute(¬eBuffer, templateData)
|
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)
|
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
var velocityBuffer bytes.Buffer
|
var velocityBuffer bytes.Buffer
|
||||||
err = mnoc.Velocity.Execute(&velocityBuffer, templateData)
|
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)
|
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))
|
payloadMessage := midi.NoteOffVelocity(uint8(channelValue), uint8(noteValue), uint8(velocityValue))
|
||||||
wrappedPayload.Payload = payloadMessage
|
wrappedPayload.Payload = payloadMessage
|
||||||
return wrappedPayload, nil
|
return wrappedPayload, nil
|
||||||
|
|||||||
@@ -35,6 +35,11 @@ func (mnoc *MIDINoteOnCreate) Process(ctx context.Context, wrappedPayload common
|
|||||||
|
|
||||||
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
var noteBuffer bytes.Buffer
|
var noteBuffer bytes.Buffer
|
||||||
err = mnoc.Note.Execute(¬eBuffer, templateData)
|
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)
|
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
var velocityBuffer bytes.Buffer
|
var velocityBuffer bytes.Buffer
|
||||||
err = mnoc.Velocity.Execute(&velocityBuffer, templateData)
|
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)
|
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))
|
payloadMessage := midi.NoteOn(uint8(channelValue), uint8(noteValue), uint8(velocityValue))
|
||||||
wrappedPayload.Payload = payloadMessage
|
wrappedPayload.Payload = payloadMessage
|
||||||
return wrappedPayload, nil
|
return wrappedPayload, nil
|
||||||
|
|||||||
@@ -34,6 +34,11 @@ func (mpcc *MIDIProgramChangeCreate) Process(ctx context.Context, wrappedPayload
|
|||||||
|
|
||||||
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
var programBuffer bytes.Buffer
|
var programBuffer bytes.Buffer
|
||||||
err = mpcc.Program.Execute(&programBuffer, templateData)
|
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)
|
programValue, err := strconv.ParseUint(programBuffer.String(), 10, 8)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
wrappedPayload.End = true
|
||||||
|
return wrappedPayload, err
|
||||||
|
}
|
||||||
|
|
||||||
payloadMessage := midi.ProgramChange(uint8(channelValue), uint8(programValue))
|
payloadMessage := midi.ProgramChange(uint8(channelValue), uint8(programValue))
|
||||||
wrappedPayload.Payload = payloadMessage
|
wrappedPayload.Payload = payloadMessage
|
||||||
return wrappedPayload, nil
|
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 {
|
if err != nil {
|
||||||
wrappedPayload.End = true
|
wrappedPayload.End = true
|
||||||
|
|||||||
@@ -209,6 +209,13 @@ func TestBadScriptJS(t *testing.T) {
|
|||||||
Params: test.params,
|
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})
|
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user