mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 21:05:30 +00:00
cleanup error messages
This commit is contained in:
@@ -21,13 +21,13 @@ func init() {
|
||||
|
||||
duration, ok := params["duration"]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("interval requires a duration parameter")
|
||||
return nil, fmt.Errorf("gen.interval requires a duration parameter")
|
||||
}
|
||||
|
||||
durationNum, ok := duration.(float64)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("interval duration must be number")
|
||||
return nil, fmt.Errorf("gen.interval duration must be number")
|
||||
}
|
||||
|
||||
return &Interval{Duration: uint32(durationNum), config: config}, nil
|
||||
@@ -51,14 +51,15 @@ func (i *Interval) Run() error {
|
||||
ticker := time.NewTicker(time.Millisecond * time.Duration(i.Duration))
|
||||
i.ticker = ticker
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-i.router.Context.Done():
|
||||
slog.Debug("router context done in module", "id", i.config.Id)
|
||||
return nil
|
||||
case t := <-ticker.C:
|
||||
case <-ticker.C:
|
||||
if i.router != nil {
|
||||
i.router.HandleInput(i.config.Id, t)
|
||||
i.router.HandleInput(i.config.Id, time.Now())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func init() {
|
||||
input, ok := params["input"]
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("net.mqtt.client requires a input parameter")
|
||||
return nil, fmt.Errorf("misc.midi.client requires a input parameter")
|
||||
}
|
||||
|
||||
inputString, ok := input.(string)
|
||||
@@ -39,7 +39,7 @@ func init() {
|
||||
output, ok := params["output"]
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("net.mqtt.client requires a output parameter")
|
||||
return nil, fmt.Errorf("misc.midi.client requires a output parameter")
|
||||
}
|
||||
|
||||
outputString, ok := output.(string)
|
||||
|
||||
@@ -31,7 +31,7 @@ func init() {
|
||||
brokerString, ok := broker.(string)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("net.mqtt.client host must be string")
|
||||
return nil, fmt.Errorf("net.mqtt.client broker must be string")
|
||||
}
|
||||
|
||||
topic, ok := params["topic"]
|
||||
@@ -43,7 +43,7 @@ func init() {
|
||||
topicString, ok := topic.(string)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("net.mqtt.client host must be string")
|
||||
return nil, fmt.Errorf("net.mqtt.client topic must be string")
|
||||
}
|
||||
|
||||
clientId, ok := params["clientId"]
|
||||
@@ -55,7 +55,7 @@ func init() {
|
||||
clientIdString, ok := clientId.(string)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("net.mqtt.client host must be string")
|
||||
return nil, fmt.Errorf("net.mqtt.client clientId must be string")
|
||||
}
|
||||
|
||||
return &MQTTClient{config: config, Broker: brokerString, Topic: topicString, ClientID: clientIdString}, nil
|
||||
@@ -108,7 +108,7 @@ func (mc *MQTTClient) Output(payload any) error {
|
||||
payloadMessage, ok := payload.(processing.MQTTMessage)
|
||||
|
||||
if !ok {
|
||||
return fmt.Errorf("net.mqtt.client is only able to output MQTTMessage")
|
||||
return fmt.Errorf("net.mqtt.client is only able to output a MQTTMessage")
|
||||
}
|
||||
|
||||
if mc.client == nil {
|
||||
|
||||
@@ -31,7 +31,7 @@ func init() {
|
||||
hostString, ok := host.(string)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("net.tcp.client host must be uint16")
|
||||
return nil, fmt.Errorf("net.tcp.client host must be string")
|
||||
}
|
||||
|
||||
port, ok := params["port"]
|
||||
@@ -42,7 +42,7 @@ func init() {
|
||||
portNum, ok := port.(float64)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("net.tcp.client port must be uint16")
|
||||
return nil, fmt.Errorf("net.tcp.client port must be a number")
|
||||
}
|
||||
|
||||
addr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", hostString, uint16(portNum)))
|
||||
@@ -58,7 +58,7 @@ func init() {
|
||||
framingMethodString, ok := framingMethod.(string)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("tcp framing method must be a string")
|
||||
return nil, fmt.Errorf("net.tcp.client framing method must be a string")
|
||||
}
|
||||
|
||||
var framer framing.Framer
|
||||
|
||||
@@ -33,7 +33,7 @@ func init() {
|
||||
portNum, ok := port.(float64)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("net.tcp.server port must be uint16")
|
||||
return nil, fmt.Errorf("net.tcp.server port must be a number")
|
||||
}
|
||||
|
||||
framingMethod, ok := params["framing"]
|
||||
@@ -44,7 +44,7 @@ func init() {
|
||||
framingMethodString, ok := framingMethod.(string)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("tcp framing method must be a string")
|
||||
return nil, fmt.Errorf("net.tcp.server framing method must be a string")
|
||||
}
|
||||
|
||||
ipString := "0.0.0.0"
|
||||
@@ -55,7 +55,7 @@ func init() {
|
||||
specificIpString, ok := ip.(string)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("tcp ip method must be a string")
|
||||
return nil, fmt.Errorf("net.tcp.server ip must be a string")
|
||||
}
|
||||
ipString = specificIpString
|
||||
}
|
||||
@@ -120,7 +120,7 @@ ClientRead:
|
||||
if ts.router != nil {
|
||||
ts.router.HandleInput(ts.config.Id, message)
|
||||
} else {
|
||||
slog.Error("tcp-server has no router", "id", ts.config.Id)
|
||||
slog.Error("net.tcp.server has no router", "id", ts.config.Id)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,6 +130,7 @@ ClientRead:
|
||||
}
|
||||
|
||||
func (ts *TCPServer) Run() error {
|
||||
// TODO(jwetzell): switch to net.ListenTCP and move addr resolution to init
|
||||
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", ts.Ip, ts.Port))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
4
timer.go
4
timer.go
@@ -21,13 +21,13 @@ func init() {
|
||||
|
||||
duration, ok := params["duration"]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("timer requires a duration parameter")
|
||||
return nil, fmt.Errorf("gen.timer requires a duration parameter")
|
||||
}
|
||||
|
||||
durationNum, ok := duration.(float64)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("timer duration must be number")
|
||||
return nil, fmt.Errorf("gen.timer duration must be a number")
|
||||
}
|
||||
|
||||
return &Timer{Duration: uint32(durationNum), config: config}, nil
|
||||
|
||||
@@ -29,7 +29,7 @@ func init() {
|
||||
hostString, ok := host.(string)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("net.udp.client host must be uint16")
|
||||
return nil, fmt.Errorf("net.udp.client host must be a string")
|
||||
}
|
||||
|
||||
port, ok := params["port"]
|
||||
|
||||
@@ -28,7 +28,7 @@ func init() {
|
||||
portNum, ok := port.(float64)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("net.udp.server port must be uint16")
|
||||
return nil, fmt.Errorf("net.udp.server port must be a number")
|
||||
}
|
||||
|
||||
ipString := "0.0.0.0"
|
||||
@@ -39,7 +39,7 @@ func init() {
|
||||
specificIpString, ok := ip.(string)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("tcp ip method must be a string")
|
||||
return nil, fmt.Errorf("net.udp.server ip must be a string")
|
||||
}
|
||||
ipString = specificIpString
|
||||
}
|
||||
@@ -63,6 +63,7 @@ func (us *UDPServer) RegisterRouter(router *Router) {
|
||||
|
||||
func (us *UDPServer) Run() error {
|
||||
|
||||
// TODO(jwetzell): move this to init
|
||||
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", us.Ip, us.Port))
|
||||
if err != nil {
|
||||
log.Fatalf("error resolving UDP address: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user