| | | 1 | | namespace Elsa.Workflows.Exceptions; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Represents a privacy-safe failure while converting an activity output's bound value. |
| | | 5 | | /// </summary> |
| | | 6 | | public class OutputConversionException : Exception, ISafeExceptionMetadataProvider |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Initializes a new output conversion exception. |
| | | 10 | | /// </summary> |
| | | 11 | | public OutputConversionException( |
| | | 12 | | string converterId, |
| | | 13 | | OutputConversionFailureStage stage, |
| | | 14 | | string activityId, |
| | | 15 | | string activityType, |
| | | 16 | | string outputName, |
| | | 17 | | string? destinationId, |
| | | 18 | | Type sourceType, |
| | | 19 | | Type? destinationType, |
| | | 20 | | Exception? innerException = null) |
| | 10 | 21 | | : base(CreateMessage(converterId, stage, activityId, outputName), innerException) |
| | | 22 | | { |
| | 10 | 23 | | ConverterId = converterId; |
| | 10 | 24 | | Stage = stage; |
| | 10 | 25 | | ActivityId = activityId; |
| | 10 | 26 | | ActivityType = activityType; |
| | 10 | 27 | | OutputName = outputName; |
| | 10 | 28 | | DestinationId = destinationId; |
| | 10 | 29 | | SourceTypeName = sourceType.FullName ?? sourceType.Name; |
| | 10 | 30 | | DestinationTypeName = destinationType?.FullName; |
| | 10 | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <summary>The configured converter ID.</summary> |
| | 3 | 34 | | public string ConverterId { get; } |
| | | 35 | | |
| | | 36 | | /// <summary>The stage at which conversion failed.</summary> |
| | 11 | 37 | | public OutputConversionFailureStage Stage { get; } |
| | | 38 | | |
| | | 39 | | /// <summary>The definition ID of the activity producing the output.</summary> |
| | 3 | 40 | | public string ActivityId { get; } |
| | | 41 | | |
| | | 42 | | /// <summary>The activity type name.</summary> |
| | 3 | 43 | | public string ActivityType { get; } |
| | | 44 | | |
| | | 45 | | /// <summary>The declared output name.</summary> |
| | 3 | 46 | | public string OutputName { get; } |
| | | 47 | | |
| | | 48 | | /// <summary>The optional destination ID.</summary> |
| | 6 | 49 | | public string? DestinationId { get; } |
| | | 50 | | |
| | | 51 | | /// <summary>The declared source type name.</summary> |
| | 3 | 52 | | public string SourceTypeName { get; } |
| | | 53 | | |
| | | 54 | | /// <summary>The optional declared destination type name.</summary> |
| | 6 | 55 | | public string? DestinationTypeName { get; } |
| | | 56 | | |
| | | 57 | | /// <inheritdoc /> |
| | | 58 | | public IReadOnlyDictionary<string, string> GetSafeMetadata() |
| | | 59 | | { |
| | 3 | 60 | | var metadata = new Dictionary<string, string>(StringComparer.Ordinal) |
| | 3 | 61 | | { |
| | 3 | 62 | | [nameof(ConverterId)] = ConverterId, |
| | 3 | 63 | | [nameof(Stage)] = Stage.ToString(), |
| | 3 | 64 | | [nameof(ActivityId)] = ActivityId, |
| | 3 | 65 | | [nameof(ActivityType)] = ActivityType, |
| | 3 | 66 | | [nameof(OutputName)] = OutputName, |
| | 3 | 67 | | [nameof(SourceTypeName)] = SourceTypeName |
| | 3 | 68 | | }; |
| | | 69 | | |
| | 3 | 70 | | if (DestinationId != null) |
| | 3 | 71 | | metadata[nameof(DestinationId)] = DestinationId; |
| | | 72 | | |
| | 3 | 73 | | if (DestinationTypeName != null) |
| | 3 | 74 | | metadata[nameof(DestinationTypeName)] = DestinationTypeName; |
| | | 75 | | |
| | 3 | 76 | | return metadata; |
| | | 77 | | } |
| | | 78 | | |
| | | 79 | | private static string CreateMessage(string converterId, OutputConversionFailureStage stage, string activityId, strin |
| | 10 | 80 | | $"Output converter '{converterId}' failed during {stage} for output '{outputName}' of activity '{activityId}'."; |
| | | 81 | | } |