| | | 1 | | using System.Text.Json.Serialization; |
| | | 2 | | |
| | | 3 | | // ReSharper disable NotAccessedPositionalProperty.Global |
| | | 4 | | |
| | | 5 | | namespace Elsa.Workflows.State; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// A simplified, serializable model representing an exception. |
| | | 9 | | /// </summary> |
| | 49 | 10 | | public record ExceptionState( |
| | 28 | 11 | | Type Type, |
| | 54 | 12 | | string Message, |
| | 23 | 13 | | string? StackTrace, |
| | 73 | 14 | | ExceptionState? InnerException) |
| | | 15 | | { |
| | | 16 | | /// <summary> |
| | | 17 | | /// Gets privacy-safe structured exception metadata. |
| | | 18 | | /// </summary> |
| | 79 | 19 | | public IReadOnlyDictionary<string, string>? Metadata { get; init; } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Constructor |
| | | 23 | | /// </summary> |
| | | 24 | | [JsonConstructor] |
| | 1 | 25 | | public ExceptionState() : this(default!, default!, default, default) |
| | | 26 | | { |
| | | 27 | | |
| | 1 | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Creates a new <see cref="ExceptionState"/> from the specified exception. |
| | | 32 | | /// </summary> |
| | | 33 | | public static ExceptionState? FromException(Exception? ex) |
| | | 34 | | { |
| | 3502 | 35 | | if (ex == null) |
| | 3455 | 36 | | return null; |
| | | 37 | | |
| | 47 | 38 | | var metadataProvider = ex as ISafeExceptionMetadataProvider; |
| | 47 | 39 | | var metadata = metadataProvider?.GetSafeMetadata(); |
| | 47 | 40 | | var innerException = metadataProvider == null ? FromException(ex.InnerException) : null; |
| | | 41 | | |
| | 47 | 42 | | return new ExceptionState(ex.GetType(), ex.Message, ex.StackTrace, innerException) |
| | 47 | 43 | | { |
| | 47 | 44 | | Metadata = metadata |
| | 47 | 45 | | }; |
| | | 46 | | } |
| | | 47 | | } |