0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00

fix: prevent crash when parsing invalid JSON in memory messages (#3280)

## Overview
Improved error handling in the memory component's JSON parsing to
prevent crashes when parsing invalid JSON content.

## Problem
The application would crash when the memory component encountered
strings starting with '[' or '{' that were not valid JSON. The
parseMessages method was attempting to parse these strings as JSON
without proper error handling, resulting in uncaught exceptions.

## Changes
Implemented a try-catch block in the parseMessages method when
attempting to parse JSON, ensuring the application properly handles
exceptions. This allows the application to continue using the original
string content instead of crashing when invalid JSON is encountered.

## Testing
- Verified that the application works correctly with both valid and
invalid JSON cases
- Confirmed there is no impact on existing functionality
- Tested with strings that start with '[' or '{' but are not valid JSON
to ensure they are handled gracefully
This commit is contained in:
ニケちゃん / nikechan 2025-03-27 20:57:06 +01:00 • committed by GitHub
commit 107bcfe5bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 9 deletions