Skip to content

Commit 079beef

Browse files
committed
inform if unable to parse the saga state changes
1 parent 49e8b54 commit 079beef

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

src/Frontend/src/components/messages2/SagaDiagram/SagaDiagramParser.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export interface SagaUpdateViewModel {
3737
HasOutgoingMessages: boolean;
3838
HasOutgoingTimeoutMessages: boolean;
3939
showUpdatedPropertiesOnly: boolean;
40-
stateAfterChange: Record<string, unknown>;
41-
previousStateAfterChange?: Record<string, unknown>;
40+
stateAfterChange: string;
41+
previousStateAfterChange?: string;
4242
}
4343

4444
export interface SagaViewModel {
@@ -63,14 +63,6 @@ export function parseSagaUpdates(sagaHistory: SagaHistory | null, messagesData:
6363
const finishTime = new Date(update.finish_time);
6464
const initiatingMessageTimestamp = new Date(update.initiating_message?.time_sent || Date.now());
6565

66-
// Parse the state_after_change JSON
67-
let stateAfterChange: Record<string, unknown> = {};
68-
try {
69-
stateAfterChange = JSON.parse(update.state_after_change || "{}");
70-
} catch (e) {
71-
console.error("Error parsing state_after_change:", e);
72-
}
73-
7466
// Find message data for initiating message
7567
const initiatingMessageData = update.initiating_message ? messagesData.find((m) => m.message_id === update.initiating_message.message_id)?.data || [] : [];
7668

@@ -135,7 +127,7 @@ export function parseSagaUpdates(sagaHistory: SagaHistory | null, messagesData:
135127
HasOutgoingMessages: regularMessages.length > 0,
136128
HasOutgoingTimeoutMessages: outgoingTimeoutMessages.length > 0,
137129
showUpdatedPropertiesOnly: true, // Default to showing only updated properties
138-
stateAfterChange: stateAfterChange,
130+
stateAfterChange: update.state_after_change || "{}",
139131
};
140132
})
141133
.sort((a, b) => a.StartTime.getTime() - b.StartTime.getTime())

src/Frontend/src/components/messages2/SagaDiagram/SagaUpdateNode.vue

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const props = defineProps<{
3030
const store = useSagaDiagramStore();
3131
const initiatingMessageRef = ref<HTMLElement | null>(null);
3232
const isActive = ref(false);
33+
const hasParsingError = ref(false);
3334
3435
// Watch for changes to selectedMessageId
3536
watch(
@@ -61,33 +62,30 @@ const formatJsonValue = (value: unknown): string => {
6162
};
6263
6364
// Process JSON state and remove standard properties
64-
const processState = (state: unknown): Record<string, JsonValue> => {
65+
const processState = (state: string | undefined): Record<string, JsonValue> => {
6566
if (!state) return {};
6667
6768
let stateObj: Record<string, unknown>;
6869
try {
69-
stateObj = typeof state === "string" ? JSON.parse(state) : (state as Record<string, unknown>);
70+
stateObj = JSON.parse(state);
7071
} catch (e) {
7172
console.error("Error parsing state:", e);
73+
hasParsingError.value = true;
7274
return {};
7375
}
7476
75-
// Filter out standard properties
77+
// Filter out standard properties using delete
7678
const standardKeys = ["$type", "Id", "Originator", "OriginalMessageId"];
77-
const filteredState: Record<string, JsonValue> = {};
78-
79-
Object.keys(stateObj).forEach((key) => {
80-
if (!standardKeys.includes(key)) {
81-
// Type assertion here since we can't guarantee the type exactly matches JsonValue
82-
filteredState[key] = stateObj[key] as JsonValue;
79+
standardKeys.forEach((key) => {
80+
if (key in stateObj) {
81+
delete stateObj[key];
8382
}
8483
});
8584
86-
return filteredState;
85+
return stateObj as Record<string, JsonValue>;
8786
};
8887
89-
// Compute the diff between current and previous states
90-
const stateDiff = computed(() => {
88+
const sagaUpdateStateChanges = computed(() => {
9189
const currentState = processState(props.update.stateAfterChange);
9290
const previousState = processState(props.update.previousStateAfterChange);
9391
const isFirstNode = props.update.IsFirstNode;
@@ -175,9 +173,14 @@ const hasStateChanges = computed(() => {
175173
<h3 class="saga-state-title" v-if="update.IsFirstNode">Initial Saga State</h3>
176174
<h3 class="saga-state-title" v-else>State Changes</h3>
177175

176+
<!-- Error message when parsing fails -->
177+
<div v-if="hasParsingError" class="json-container">
178+
<div class="parsing-error-message">An error occurred while parsing and displaying the saga state for this update</div>
179+
</div>
180+
178181
<!-- Initial state display -->
179-
<div v-if="update.IsFirstNode" class="json-container">
180-
<CodeEditor css="monospace-code" :model-value="stateDiff.formattedState || ''" language="json" :showCopyToClipboard="false" :showGutter="false" />
182+
<div v-else-if="update.IsFirstNode" class="json-container">
183+
<CodeEditor css="monospace-code" :model-value="sagaUpdateStateChanges.formattedState || ''" language="json" :showCopyToClipboard="false" :showGutter="false" />
181184
</div>
182185

183186
<!-- No changes message -->
@@ -187,7 +190,7 @@ const hasStateChanges = computed(() => {
187190

188191
<!-- Side-by-side diff view for state changes -->
189192
<div v-else-if="hasStateChanges && !update.IsFirstNode">
190-
<DiffViewer :hide-line-numbers="true" :showDiffOnly="true" :oldValue="stateDiff.previousFormatted" :newValue="stateDiff.currentFormatted" leftTitle="Previous State" rightTitle="Updated State" />
193+
<DiffViewer :hide-line-numbers="true" :showDiffOnly="true" :oldValue="sagaUpdateStateChanges.previousFormatted" :newValue="sagaUpdateStateChanges.currentFormatted" leftTitle="Previous State" rightTitle="Updated State" />
191194
</div>
192195
</div>
193196
</div>
@@ -403,6 +406,13 @@ const hasStateChanges = computed(() => {
403406
color: #666;
404407
}
405408
409+
.parsing-error-message {
410+
padding: 1rem;
411+
text-align: center;
412+
font-style: italic;
413+
color: #a94442;
414+
}
415+
406416
/* Monospace font styling that matches DiffViewer */
407417
:deep(.monospace-code) {
408418
border-radius: 0;

0 commit comments

Comments
 (0)