Skip to content

Commit b314a05

Browse files
committed
Adds SerializerException for serialization errors
Introduces a base exception type for serialization-specific error conditions. This allows for a more unified error handling approach, especially in testing and when using custom serializers. Also documents the new exception and other component exception types.
1 parent 77727cd commit b314a05

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

docs/guide/serialization.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,28 @@ var storage = new InMemoryFileStorage(o => o.Serializer = serializer);
266266

267267
For DI configuration and shared options across implementations, see [Dependency Injection](/guide/dependency-injection).
268268

269+
## Serialization Exceptions
270+
271+
Foundatio provides `SerializerException` as a base exception type for serialization-specific error conditions. **Built-in serializers** (System.Text.Json, Newtonsoft.Json, MessagePack) throw their native exceptions (e.g., `JsonException`, `MessagePackSerializationException`). `SerializerException` is primarily used for:
272+
273+
- **Testing**: The `FaultInjectingSerializer` in `Foundatio.TestHarness` throws `SerializerException` to simulate serialization failures in unit and integration tests
274+
- **Custom serializers**: Wrap implementation-specific exceptions when you want a unified exception type across your application
275+
276+
### Component-Specific Exception Types
277+
278+
Foundatio provides dedicated exception types for each infrastructure component:
279+
280+
| Component | Exception Type | Namespace |
281+
|-----------|---------------|-----------|
282+
| Caching | `CacheException` | `Foundatio.Caching` |
283+
| Queues | `QueueException` | `Foundatio.Queues` |
284+
| Messaging | `MessageBusException` | `Foundatio.Messaging` |
285+
| Storage | `StorageException` | `Foundatio.Storage` |
286+
| Serialization | `SerializerException` | `Foundatio.Serializer` |
287+
| Resilience | `BrokenCircuitException` | `Foundatio.Resilience` |
288+
289+
These ensure consumers get predictable exception types regardless of the underlying implementation (Redis, Azure, AWS, etc.).
290+
269291
## Serialization Considerations
270292

271293
### Binary vs Text Serializers
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace Foundatio.Serializer;
4+
5+
/// <summary>
6+
/// Exception thrown for serialization and deserialization errors.
7+
/// </summary>
8+
public class SerializerException : Exception
9+
{
10+
public SerializerException(string message) : base(message)
11+
{
12+
}
13+
14+
public SerializerException(string message, Exception innerException) : base(message, innerException)
15+
{
16+
}
17+
}

0 commit comments

Comments
 (0)