mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(Google Sheets Node): Improve error message when row_number is null or undefined (#14229)
This commit is contained in:
@@ -204,4 +204,46 @@ describe('Google Sheet - Update', () => {
|
|||||||
'USER_ENTERED',
|
'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.',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
|
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 { cellFormat, handlingExtraData, locationDefine } from './commonDescription';
|
||||||
import type { GoogleSheet } from '../../helpers/GoogleSheet';
|
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
|
// Setting empty values to empty string so that they are not ignored by the API
|
||||||
Object.keys(mappingValues).forEach((key) => {
|
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) {
|
if (mappingValues[key] === undefined || mappingValues[key] === null) {
|
||||||
mappingValues[key] = '';
|
mappingValues[key] = '';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user