Skip to content

Commit 40b4092

Browse files
aali309chzar
authored andcommitted
feat: improve StatefulSet immutable field error messages (argoproj#21209)
Signed-off-by: Atif Ali <[email protected]>
1 parent bdcfa5a commit 40b4092

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

ui/src/app/applications/components/application-operation-state/application-operation-state.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,24 @@ export const ApplicationOperationState: React.StatelessComponent<Props> = ({appl
5858
const operationAttributes = [
5959
{title: 'OPERATION', value: utils.getOperationType(application)},
6060
{title: 'PHASE', value: operationState.phase},
61-
...(operationState.message ? [{title: 'MESSAGE', value: operationState.message}] : []),
61+
...(operationState.message
62+
? [
63+
{
64+
title: 'MESSAGE',
65+
value: (
66+
<pre
67+
style={{
68+
whiteSpace: 'pre-wrap',
69+
wordBreak: 'break-word',
70+
margin: 0,
71+
fontFamily: 'inherit'
72+
}}>
73+
{utils.formatOperationMessage(operationState.message)}
74+
</pre>
75+
)
76+
}
77+
]
78+
: []),
6279
{title: 'STARTED AT', value: <Timestamp date={operationState.startedAt} />},
6380
{
6481
title: 'DURATION',

ui/src/app/applications/components/utils.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,44 @@ export function formatCreationTimestamp(creationTimestamp: string) {
15471547
);
15481548
}
15491549

1550+
/*
1551+
* formatStatefulSetChange reformats a single line describing changes to immutable fields in a StatefulSet.
1552+
* It extracts the field name and its "from" and "to" values for better readability.
1553+
*/
1554+
function formatStatefulSetChange(line: string): string {
1555+
if (line.startsWith('-')) {
1556+
// Remove leading "- " from the line and split into field and changes
1557+
const [field, changes] = line.substring(2).split(':');
1558+
if (changes) {
1559+
// Split "from: X to: Y" into separate lines with aligned values
1560+
const [from, to] = changes.split('to:').map(s => s.trim());
1561+
return ` - ${field}:\n from: ${from.replace('from:', '').trim()}\n to: ${to}`;
1562+
}
1563+
}
1564+
return line;
1565+
}
1566+
1567+
export function formatOperationMessage(message: string): string {
1568+
if (!message) {
1569+
return message;
1570+
}
1571+
1572+
// Format immutable fields error message
1573+
if (message.includes('attempting to change immutable fields:')) {
1574+
const [header, ...details] = message.split('\n');
1575+
const formattedDetails = details
1576+
// Remove empty lines
1577+
.filter(line => line.trim())
1578+
// Use helper function
1579+
.map(formatStatefulSetChange)
1580+
.join('\n');
1581+
1582+
return `${header}\n${formattedDetails}`;
1583+
}
1584+
1585+
return message;
1586+
}
1587+
15501588
export const selectPostfix = (arr: string[], singular: string, plural: string) => (arr.length > 1 ? plural : singular);
15511589

15521590
export function getUsrMsgKeyToDisplay(appName: string, msgKey: string, usrMessages: appModels.UserMessages[]) {

0 commit comments

Comments
 (0)