Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/app/src/cli/commands/app/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {linkedAppContext} from '../../services/app-context.js'
import {storeContext} from '../../services/store-context.js'
import {executeBulkOperation} from '../../services/bulk-operations/execute-bulk-operation.js'
import {globalFlags} from '@shopify/cli-kit/node/cli'
import {readStdin} from '@shopify/cli-kit/node/system'
import {readStdinString} from '@shopify/cli-kit/node/system'
import {AbortError} from '@shopify/cli-kit/node/error'

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

const query = flags.query ?? (await readStdin())
const query = flags.query ?? (await readStdinString())
if (!query) {
throw new AbortError(
'No query provided. Use the --query flag or pipe input via stdin.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,4 +459,27 @@ describe('executeBulkOperation', () => {
)
},
)
test('throws BugError and renders warning when bulk operation response returns null with no errors', async () => {
const query = '{ products { edges { node { id } } } }'
const mockResponse = {
bulkOperation: null,
userErrors: [],
}
vi.mocked(runBulkOperationQuery).mockResolvedValue(mockResponse)

await expect(
executeBulkOperation({
remoteApp: mockRemoteApp,
storeFqdn,
query,
}),
).rejects.toThrow('Bulk operation response returned null with no error message.')

expect(renderWarning).toHaveBeenCalledWith({
headline: 'Bulk operation not created succesfully.',
body: 'This is an unexpected error. Please try again later.',
})

expect(renderSuccess).not.toHaveBeenCalled()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ export async function executeBulkOperation(input: ExecuteBulkOperationInput): Pr
} else {
await renderBulkOperationResult(createdOperation, outputFile)
}
} else {
renderWarning({
headline: 'Bulk operation not created succesfully.',
body: 'This is an unexpected error. Please try again later.',
})
throw new BugError('Bulk operation response returned null with no error message.')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly sure if BugError is the right way to throw alerts here. @nickwesselman Is there a way CLI convention for this?

}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/cli-kit/src/public/node/system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ describe('isStdinPiped', () => {
})
})

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

// When
const got = await system.readStdin()
const got = await system.readStdinString()

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

// When
const got = await system.readStdin()
const got = await system.readStdinString()

// Then
expect(got).toBe('hello world')
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-kit/src/public/node/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export function isStdinPiped(): boolean {
*
* @returns A promise that resolves with the stdin content, or undefined if stdin is a TTY.
*/
export async function readStdin(): Promise<string | undefined> {
export async function readStdinString(): Promise<string | undefined> {
if (!isStdinPiped()) {
return undefined
}
Expand Down