Skip to content

Commit

Permalink
Fix null handling and default value assignments in components (#337)
Browse files Browse the repository at this point in the history
Adjusted multiple properties and variables to explicitly use null instead of default values, ensuring consistency and clarity in initialization. Added fallback logic for cases where execution details or outputs are unavailable, enhancing application stability.
  • Loading branch information
sfmskywalker authored Dec 12, 2024
1 parent d820fec commit 134318c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public record ActivityExecutionRecordTableRow(int Number, ActivityExecutionRecor
[Parameter] public int VisiblePaneHeight { get; set; }

/// The activity to display details for.
[Parameter] public JsonObject Activity { get; set; } = default!;
[Parameter] public JsonObject Activity { get; set; } = null!;

/// The latest activity execution record. Used for displaying the last state of the activity.
[Parameter] public ActivityExecutionRecord? LastActivityExecution { get; set; }

[Inject] private IActivityRegistry ActivityRegistry { get; set; } = default!;
[Inject] private IActivityRegistry ActivityRegistry { get; set; } = null!;

private ActivityExecutionRecord? SelectedItem { get; set; } = default!;
private ActivityExecutionRecord? SelectedItem { get; set; } = null!;

private IDictionary<string, DataPanelItem> ActivityInfo { get; set; } = new Dictionary<string, DataPanelItem>();
private IDictionary<string, DataPanelItem> ActivityData { get; set; } = new Dictionary<string, DataPanelItem>();
Expand Down Expand Up @@ -66,9 +66,9 @@ private void CreateDataModels()
var activityName = activity.GetName();
var activityType = activity.GetTypeName();
var execution = LastActivityExecution;
var activityVersion = execution?.ActivityTypeVersion;
var activityVersion = activity.GetVersion();
var exception = execution?.Exception;
var workflowDefinitionId = activity.GetIsWorkflowDefinitionActivity() ? activity.GetWorkflowDefinitionId() : default;
var workflowDefinitionId = activity.GetIsWorkflowDefinitionActivity() ? activity.GetWorkflowDefinitionId() : null;

var activityInfo = new Dictionary<string, DataPanelItem>
{
Expand Down Expand Up @@ -99,11 +99,15 @@ private void CreateDataModels()
foreach (var outputDescriptor in outputDescriptors)
{
var outputValue = outputs != null
? outputs.TryGetValue(outputDescriptor.Name, out var value) ? value : default
: default;
? outputs.TryGetValue(outputDescriptor.Name, out var value) ? value : null
: null;
outputData[outputDescriptor.Name] = new(outputValue?.ToString());
}
}
else
{
activityInfo["Status"] = new("Not executed");
}

var exceptionData = new Dictionary<string, DataPanelItem>();

Expand All @@ -112,7 +116,7 @@ private void CreateDataModels()
exceptionData["Message"] = new(exception.Message);
exceptionData["InnerException"] = new(exception.InnerException != null
? exception.InnerException.Type + ": " + exception.InnerException.Message
: default);
: null);
exceptionData["StackTrace"] = new(exception.StackTrace);
}

Expand All @@ -123,7 +127,7 @@ private void CreateDataModels()
{
foreach (var inputDescriptor in activityDescriptor.Inputs)
{
var inputValue = activityState.TryGetValue(inputDescriptor.Name, out var value) ? value : default;
var inputValue = activityState.TryGetValue(inputDescriptor.Name, out var value) ? value : null;
activityStateData[inputDescriptor.Name] = new(inputValue?.ToString());
}
}
Expand Down Expand Up @@ -151,7 +155,7 @@ private void CreateSelectedItemDataModels(ActivityExecutionRecord? record)

var outcomesData = record.Payload?.TryGetValue("Outcomes", out var outcomesValue) == true
? new Dictionary<string, string?> { ["Outcomes"] = outcomesValue.ToString()! }
: default;
: null;

var outputData = new Dictionary<string, string?>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ private async Task<ICollection<ActivityExecutionRecordSummary>> GetActivityExecu
var lastRecord = records.Last();
LastActivityExecution = await ActivityExecutionService.GetAsync(lastRecord.Id);
}
else
{
LastActivityExecution = null;
}

return records;
}
Expand Down

0 comments on commit 134318c

Please sign in to comment.