diff --git a/internal/driver/driver.go b/internal/driver/driver.go index 7f85aa1..a3d86c7 100644 --- a/internal/driver/driver.go +++ b/internal/driver/driver.go @@ -76,6 +76,19 @@ func (d *Driver) Run(ctx context.Context) error { // processChanges now takes and modifies the AppState directly. func (d *Driver) processChanges(appState *storage.AppState, scrapedBags map[string]crawler.Bag) (bool, []string) { var notifications []string + if appState == nil { + log.Println("⚠️ AppState is nil, initializing a new one.") + appState = &storage.AppState{ + Bags: make(map[string]crawler.Bag), + ChatIDs: make([]int64, 0), + } + } + + if appState.Bags == nil { + log.Println("⚠️ AppState.Bags is nil, initializing a new map.") + appState.Bags = make(map[string]crawler.Bag) + } + hasChanges := false for sku, newBag := range scrapedBags {