fix(agent): log warning when LoadAndDelete type assertion fails

Add a warning log when the type assertion from sync.Map.LoadAndDelete fails in UnsubscribeEvents, per review suggestion. This makes a mismatched type observable for debugging.
This commit is contained in:
程智超0668000959 2026-06-06 00:32:49 +08:00
parent f0f809db35
commit 6c882ec5e7

View file

@ -2,11 +2,13 @@ package agent
import ( import (
"context" "context"
"fmt"
"sync" "sync"
"sync/atomic" "sync/atomic"
"github.com/sipeed/picoclaw/pkg/bus" "github.com/sipeed/picoclaw/pkg/bus"
runtimeevents "github.com/sipeed/picoclaw/pkg/events" runtimeevents "github.com/sipeed/picoclaw/pkg/events"
"github.com/sipeed/picoclaw/pkg/logger"
) )
const defaultEventSubscriberBuffer = 16 const defaultEventSubscriberBuffer = 16
@ -90,6 +92,10 @@ func (al *AgentLoop) UnsubscribeEvents(id uint64) {
} }
sub, ok := value.(legacyEventSubscription) sub, ok := value.(legacyEventSubscription)
if !ok { if !ok {
logger.WarnCF("agent", "UnsubscribeEvents: unexpected type in subscription map", map[string]any{
"id": id,
"type": fmt.Sprintf("%T", value),
})
return return
} }
sub.cancel() sub.cancel()