mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-10 14:07:26 -06:00
Log and propagate error instead of using Fatal
This commit is contained in:
@@ -27,7 +27,9 @@ func GetId() int64 {
|
||||
func ParseTime(s string) carbon.Carbon {
|
||||
t, err := time.Parse("15:04", s)
|
||||
if err != nil {
|
||||
slog.Error(fmt.Sprintf("Failed to parse time string \"%s\"; format must be HH:MM.\n", s))
|
||||
parsingErr := fmt.Errorf("failed to parse time string \"%s\"; format must be HH:MM.: %w", s, err)
|
||||
slog.Error(parsingErr.Error())
|
||||
panic(parsingErr)
|
||||
}
|
||||
return carbon.Now().SetTimeMilli(t.Hour(), t.Minute(), 0, 0)
|
||||
}
|
||||
@@ -35,7 +37,9 @@ func ParseTime(s string) carbon.Carbon {
|
||||
func ParseDuration(s string) time.Duration {
|
||||
d, err := time.ParseDuration(s)
|
||||
if err != nil {
|
||||
slog.Error(fmt.Sprintf("Couldn't parse string duration: \"%s\" see https://pkg.go.dev/time#ParseDuration for valid time units\n", s))
|
||||
parsingErr := fmt.Errorf("couldn't parse string duration: \"%s\" see https://pkg.go.dev/time#ParseDuration for valid time units: %w", s, err)
|
||||
slog.Error(parsingErr.Error())
|
||||
panic(parsingErr)
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
@@ -141,7 +141,9 @@ func SubscribeToEventType(eventType string, conn *WebsocketWriter, ctx context.C
|
||||
}
|
||||
err := conn.WriteMessage(e, ctx)
|
||||
if err != nil {
|
||||
slog.Error("Error writing to websocket: %s\n", err)
|
||||
wrappedErr := fmt.Errorf("error writing to websocket: %w", err)
|
||||
slog.Error(wrappedErr.Error())
|
||||
panic(wrappedErr)
|
||||
}
|
||||
// m, _ := ReadMessage(conn, ctx)
|
||||
// log.Default().Println(string(m))
|
||||
|
||||
Reference in New Issue
Block a user