Skip to content

Commit 328e987

Browse files
authored
Merge pull request #6666 from Shopify/11-24-variable-validation-for-BulkOps-CLI
BugError added for unexpected response from BulkOps API
2 parents ffc6646 + 388de23 commit 328e987

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

packages/app/src/cli/commands/app/execute.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {linkedAppContext} from '../../services/app-context.js'
44
import {storeContext} from '../../services/store-context.js'
55
import {executeBulkOperation} from '../../services/bulk-operations/execute-bulk-operation.js'
66
import {globalFlags} from '@shopify/cli-kit/node/cli'
7-
import {readStdin} from '@shopify/cli-kit/node/system'
7+
import {readStdinString} from '@shopify/cli-kit/node/system'
88
import {AbortError} from '@shopify/cli-kit/node/error'
99

1010
export default class Execute extends AppLinkedCommand {
@@ -23,7 +23,7 @@ export default class Execute extends AppLinkedCommand {
2323
async run(): Promise<AppLinkedCommandOutput> {
2424
const {flags} = await this.parse(Execute)
2525

26-
const query = flags.query ?? (await readStdin())
26+
const query = flags.query ?? (await readStdinString())
2727
if (!query) {
2828
throw new AbortError(
2929
'No query provided. Use the --query flag or pipe input via stdin.',

packages/app/src/cli/services/bulk-operations/execute-bulk-operation.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,4 +459,27 @@ describe('executeBulkOperation', () => {
459459
)
460460
},
461461
)
462+
test('throws BugError and renders warning when bulk operation response returns null with no errors', async () => {
463+
const query = '{ products { edges { node { id } } } }'
464+
const mockResponse = {
465+
bulkOperation: null,
466+
userErrors: [],
467+
}
468+
vi.mocked(runBulkOperationQuery).mockResolvedValue(mockResponse)
469+
470+
await expect(
471+
executeBulkOperation({
472+
remoteApp: mockRemoteApp,
473+
storeFqdn,
474+
query,
475+
}),
476+
).rejects.toThrow('Bulk operation response returned null with no error message.')
477+
478+
expect(renderWarning).toHaveBeenCalledWith({
479+
headline: 'Bulk operation not created succesfully.',
480+
body: 'This is an unexpected error. Please try again later.',
481+
})
482+
483+
expect(renderSuccess).not.toHaveBeenCalled()
484+
})
462485
})

packages/app/src/cli/services/bulk-operations/execute-bulk-operation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ export async function executeBulkOperation(input: ExecuteBulkOperationInput): Pr
8181
} else {
8282
await renderBulkOperationResult(createdOperation, outputFile)
8383
}
84+
} else {
85+
renderWarning({
86+
headline: 'Bulk operation not created succesfully.',
87+
body: 'This is an unexpected error. Please try again later.',
88+
})
89+
throw new BugError('Bulk operation response returned null with no error message.')
8490
}
8591
}
8692

packages/cli-kit/src/public/node/system.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ describe('isStdinPiped', () => {
8888
})
8989
})
9090

91-
describe('readStdin', () => {
91+
describe('readStdinString', () => {
9292
test('returns undefined when stdin is not piped', async () => {
9393
// Given
9494
vi.mocked(fs.fstatSync).mockReturnValue({isFIFO: () => false, isFile: () => false} as fs.Stats)
9595

9696
// When
97-
const got = await system.readStdin()
97+
const got = await system.readStdinString()
9898

9999
// Then
100100
expect(got).toBeUndefined()
@@ -107,7 +107,7 @@ describe('readStdin', () => {
107107
vi.spyOn(process, 'stdin', 'get').mockReturnValue(mockStdin as unknown as typeof process.stdin)
108108

109109
// When
110-
const got = await system.readStdin()
110+
const got = await system.readStdinString()
111111

112112
// Then
113113
expect(got).toBe('hello world')

packages/cli-kit/src/public/node/system.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export function isStdinPiped(): boolean {
229229
*
230230
* @returns A promise that resolves with the stdin content, or undefined if stdin is a TTY.
231231
*/
232-
export async function readStdin(): Promise<string | undefined> {
232+
export async function readStdinString(): Promise<string | undefined> {
233233
if (!isStdinPiped()) {
234234
return undefined
235235
}

0 commit comments

Comments
 (0)