@@ -105,16 +105,20 @@ def read_all(self) -> list[Feedback]:
105105 """Return all persisted :class:`~microbots.auto_memory.data_models.Feedback` entries.
106106
107107 Returns an empty list if the feedback file does not exist yet.
108+ Lines that contain invalid JSON, non-object JSON, or fields that cannot
109+ be mapped to :class:`~microbots.auto_memory.data_models.Feedback` are
110+ skipped with a ``WARNING`` log message rather than raising an exception.
108111
109112 Returns
110113 -------
111114 list[Feedback]
112- All feedback entries in the order they were appended.
115+ Successfully parsed entries in the order they were appended.
116+ Corrupt or malformed lines are omitted.
113117
114118 Raises
115119 ------
116120 MemoryStoreError
117- If not mounted or on I/O / parse error.
121+ If not mounted, or if the file cannot be opened ( I/O error) .
118122 """
119123 self ._require_mounted ()
120124 if not self ._feedback_path .exists (): # type: ignore[union-attr]
@@ -130,23 +134,32 @@ def read_all(self) -> list[Feedback]:
130134 try :
131135 data = json .loads (line )
132136 except json .JSONDecodeError as exc :
133- raise MemoryStoreError (
134- f"Invalid JSON on line { lineno } of "
135- f"{ self ._feedback_path } : { exc } "
136- ) from exc
137+ logger .warning (
138+ "Skipping corrupt JSON on line %d of %s: %s" ,
139+ lineno ,
140+ self ._feedback_path ,
141+ exc ,
142+ )
143+ continue
137144 if not isinstance (data , dict ):
138- raise MemoryStoreError (
139- f"Expected a JSON object on line { lineno } of "
140- f"{ self ._feedback_path } , got { type (data ).__name__ } "
145+ logger .warning (
146+ "Skipping non-object entry on line %d of %s (got %s)" ,
147+ lineno ,
148+ self ._feedback_path ,
149+ type (data ).__name__ ,
141150 )
151+ continue
142152 known = {f .name for f in dataclasses .fields (Feedback )}
143153 try :
144154 entries .append (Feedback (** {k : v for k , v in data .items () if k in known }))
145155 except TypeError as exc :
146- raise MemoryStoreError (
147- f"Cannot construct Feedback from line { lineno } of "
148- f"{ self ._feedback_path } : { exc } "
149- ) from exc
156+ logger .warning (
157+ "Skipping malformed Feedback on line %d of %s: %s" ,
158+ lineno ,
159+ self ._feedback_path ,
160+ exc ,
161+ )
162+ continue
150163 except OSError as exc :
151164 raise MemoryStoreError (f"Failed to read feedback: { exc } " ) from exc
152165
@@ -190,3 +203,23 @@ def _require_mounted(self) -> None:
190203 raise MemoryStoreError (
191204 "MemoryStore has not been mounted; call mount() first"
192205 )
206+
207+ @property
208+ def memory_dir (self ) -> Path :
209+ """Absolute path to the memory directory.
210+
211+ Returns
212+ -------
213+ Path
214+ The directory that holds the feedback file.
215+
216+ Raises
217+ ------
218+ MemoryStoreError
219+ If the store has not been mounted yet.
220+ """
221+ if self ._memory_dir is None :
222+ raise MemoryStoreError (
223+ "MemoryStore has not been mounted; call mount() first"
224+ )
225+ return self ._memory_dir
0 commit comments