{"record":{"id":"2636f78b99ae404d","repo":"micro/go-micro","slug":"error-writing-to-the-store","errorCode":null,"errorMessage":"Error writing to the store","messagePattern":"Error writing to the store","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"events/store.go","lineNumber":107,"sourceCode":"\n\t// construct the store record\n\tbytes, err := json.Marshal(event)\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"Error mashaling event to JSON\")\n\t}\n\t// suffix event ID with hour resolution for easy retrieval in batches\n\ttimeSuffix := time.Now().Format(\"2006010215\")\n\n\trecord := &store.Record{\n\t\t// key is such that reading by prefix indexes by topic and reading by suffix indexes by time\n\t\tKey:    event.Topic + joinKey + event.ID + joinKey + timeSuffix,\n\t\tValue:  bytes,\n\t\tExpiry: options.TTL,\n\t}\n\n\t// write the record to the store\n\tif err := s.store.Write(record); err != nil {\n\t\treturn errors.Wrap(err, \"Error writing to the store\")\n\t}\n\n\treturn nil\n}\n\nfunc (s *evStore) backupLoop() {\n\tfor {\n\t\terr := s.opts.Backup.Snapshot(s.store)\n\t\tif err != nil {\n\t\t\tlogger.Errorf(\"Error running backup %s\", err)\n\t\t}\n\n\t\ttime.Sleep(1 * time.Hour)\n\t}\n}\n\n// Backup is an interface for snapshotting the events store to long term storage\ntype Backup interface {","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/events/store.go#L89-L125","documentation":"evStore.Write writes the constructed store.Record (topic/ID/time-suffixed key, JSON value, TTL expiry) to the underlying store. This error wraps any failure returned by store.Write, meaning the event record could not be persisted.","triggerScenarios":"Calling evStore.Write when the backing store rejects the write: remote store backend unreachable or read-only, disk full for file-backed stores, invalid key characters rejected by a custom store implementation, or the store was closed.","commonSituations":"Redis/cockroach store plugin down or misconfigured credentials; storage quota or disk exhaustion; key containing characters a custom backend forbids; concurrent snapshot (backup) locking the store.","solutions":["Check errors.Cause(err) for the backend-specific reason","Verify the backing store service health, credentials, and available disk/quota","Validate the record key (event.Topic + event.ID + time suffix) is acceptable for the backend","Retry with backoff for transient backend failures","If writes keep failing, fall back to the in-memory store and alert"],"exampleFix":"// before\nif err := s.store.Write(record); err != nil { return err } // hard fail on transient blip\n// after\nif err := s.store.Write(record); err != nil {\n    return backoff.Retry(func() error { return s.store.Write(record) }, policy)\n}","handlingStrategy":"retry","validationCode":"// sanity-check the event before writing\nif event == nil || event.Topic == \"\" || event.ID == \"\" {\n    return errors.New(\"event missing topic or id\")\n}\nif _, err := json.Marshal(event); err != nil { return err }","typeGuard":null,"tryCatchPattern":"err := evStore.Write(event)\nif err != nil {\n    if strings.Contains(err.Error(), \"Error writing to the store\") {\n        cause := errors.Cause(err)\n        // retry transient failures, alert on persistent ones\n        log.Printf(\"store write failed: %v\", cause)\n    }\n    return err\n}","preventionTips":["Monitor backing store health, disk space, and quotas","Use valid key characters for your store backend","Add retry with backoff for transient write failures","Ensure the store isn't closed before writes (check lifecycle ordering)"],"tags":["store","write","persistence"],"backgroundTag":"store-write-failed","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}