fix(Google Sheets Node): Improve error message when row_number is null or undefined (#14229)

This commit is contained in:
Dana
2025-03-31 16:47:50 +02:00
committed by GitHub
parent 9ad59380b3
commit c5e2d2dddc
2 changed files with 52 additions and 1 deletions

View File

@@ -204,4 +204,46 @@ describe('Google Sheet - Update', () => {
'USER_ENTERED',
);
});
describe('row_number input error', () => {
it.each([{ rowNumber: undefined }, { rowNumber: null }])(
'displays a helpful error message when row_number is $rowNumber',
async ({ rowNumber }) => {
mockExecuteFunctions.getInputData.mockReturnValueOnce([
{
json: {
row_number: rowNumber,
name: 'name',
text: 'txt',
},
pairedItem: {
item: 0,
input: undefined,
},
},
]);
mockExecuteFunctions.getNodeParameter.mockImplementation((parameterName: string) => {
const params: { [key: string]: string | object } = {
options: {},
'options.cellFormat': 'USER_ENTERED',
'columns.matchingColumns': ['row_number'],
'columns.value': {
row_number: rowNumber, // TODO: Test for undefined
},
dataMode: 'defineBelow',
};
return params[parameterName];
});
mockGoogleSheet.getData.mockResolvedValueOnce([['macarena'], ['boomboom']]);
mockGoogleSheet.getColumnValues.mockResolvedValueOnce([]);
await expect(execute.call(mockExecuteFunctions, mockGoogleSheet, 'Sheet1')).rejects.toThrow(
'Column to match on (row_number) is not defined. Since the field is used to determine the row to update, it needs to have a value set.',
);
},
);
});
});

View File

@@ -1,5 +1,5 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { NodeOperationError, UserError } from 'n8n-workflow';
import { cellFormat, handlingExtraData, locationDefine } from './commonDescription';
import type { GoogleSheet } from '../../helpers/GoogleSheet';
@@ -369,6 +369,15 @@ export async function execute(
}
// Setting empty values to empty string so that they are not ignored by the API
Object.keys(mappingValues).forEach((key) => {
if (
key === 'row_number' &&
(mappingValues[key] === null || mappingValues[key] === undefined)
) {
throw new UserError(
'Column to match on (row_number) is not defined. Since the field is used to determine the row to update, it needs to have a value set.',
);
}
if (mappingValues[key] === undefined || mappingValues[key] === null) {
mappingValues[key] = '';
}