Skip to content

Commit 76fb20f

Browse files
committed
better error message when org not whitelisted
1 parent 0f73a9e commit 76fb20f

File tree

4 files changed

+21
-29
lines changed

4 files changed

+21
-29
lines changed

packages/store/src/commands/store/copy.test.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {MockApiClient} from '../../services/store/mock/mock-api-client.js'
77
import {ensureOrgHasBulkDataAccess} from '../../services/store/utils/store-utils.js'
88
import {describe, vi, expect, test, beforeEach} from 'vitest'
99
import {Config, loadHelpClass} from '@oclif/core'
10-
import {renderError} from '@shopify/cli-kit/node/ui'
1110

1211
vi.mock('@shopify/cli-kit/node/ui')
1312
vi.mock('../../services/store/operations/store-copy.js')
@@ -168,19 +167,6 @@ describe('Copy', () => {
168167
)
169168
})
170169

171-
test('should throw error when no organizations have access to bulk data operations', async () => {
172-
vi.mocked(ensureOrgHasBulkDataAccess).mockResolvedValue(false)
173-
174-
await expect(run(['--fromStore=source.myshopify.com', '--toStore=target.myshopify.com'])).rejects.toThrow(
175-
'Process exit called',
176-
)
177-
expect(renderError).toHaveBeenCalledWith({
178-
headline: 'Operation failed',
179-
body: `This command is only available to Early Access Program members.`,
180-
})
181-
expect(process.exit).toHaveBeenCalledWith(1)
182-
})
183-
184170
test('should show help when invalid flag combination', async () => {
185171
await run(['--toFile=output.sqlite'])
186172

packages/store/src/commands/store/copy.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {StoreImportOperation} from '../../services/store/operations/store-import
88
import {ApiClient} from '../../services/store/api/api-client.js'
99
import {MockApiClient} from '../../services/store/mock/mock-api-client.js'
1010
import {Organization} from '../../apis/destinations/index.js'
11-
import {ensureOrgHasBulkDataAccess} from '../../services/store/utils/store-utils.js'
1211
import {globalFlags} from '@shopify/cli-kit/node/cli'
1312
import {joinPath, cwd} from '@shopify/cli-kit/node/path'
1413
import {loadHelpClass} from '@oclif/core'
@@ -33,18 +32,6 @@ export default class Copy extends BaseBDCommand {
3332
const bpSession = await apiClient.ensureAuthenticatedBusinessPlatform()
3433
const allOrgs = await apiClient.fetchOrganizations(bpSession)
3534

36-
const accessChecks = await Promise.all(
37-
allOrgs.map(async (org) => ({
38-
org,
39-
hasAccess: await ensureOrgHasBulkDataAccess(org.id, bpSession, apiClient),
40-
})),
41-
)
42-
43-
const orgsWithAccess = accessChecks.filter(({hasAccess}) => hasAccess).map(({org}) => org)
44-
if (orgsWithAccess.length === 0) {
45-
throw new Error(`This command is only available to Early Access Program members.`)
46-
}
47-
4835
const {fromStore, toStore, fromFile, _} = this.flags
4936
let {toFile} = this.flags
5037
const operationMode = this.determineOperationMode(fromStore, toStore, fromFile, toFile)
@@ -59,7 +46,7 @@ export default class Copy extends BaseBDCommand {
5946
toFile = joinPath(cwd(), `${storeDomain}-export-${Date.now()}.sqlite`)
6047
}
6148

62-
const operation = this.getOperation(operationMode, bpSession, apiClient, orgsWithAccess)
49+
const operation = this.getOperation(operationMode, bpSession, apiClient, allOrgs)
6350
const source = fromStore ?? fromFile
6451
const destination = toStore ?? toFile
6552
await operation.execute(source as string, destination as string, this.flags)

packages/store/src/lib/base-command.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {FlagOptions} from './types.js'
2+
import {checkForUndefinedFieldError} from '../services/store/utils/graphql-errors.js'
23
import Command from '@shopify/cli-kit/node/base-command'
34
import {renderError} from '@shopify/cli-kit/node/ui'
45

@@ -12,9 +13,13 @@ export abstract class BaseBDCommand extends Command {
1213
await this.runCommand()
1314
} catch (error) {
1415
if (error instanceof Error) {
16+
let errorMessage = error.message || 'An unknown error occurred'
17+
if (checkForUndefinedFieldError(error)) {
18+
errorMessage = `This command is in Early Accesss and is not yet available for the requested store(s).`
19+
}
1520
renderError({
1621
headline: `Operation failed`,
17-
body: error.message,
22+
body: errorMessage,
1823
})
1924
process.exit(1)
2025
} else {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export function checkForUndefinedFieldError(error: Error): boolean {
2+
if (error.name === 'GraphQLClientError') {
3+
const graphQLError = error as Error & {
4+
errors?: {message: string; extensions?: {code: string; fieldName: string}}[]
5+
}
6+
if (graphQLError.errors && graphQLError.errors.length > 0) {
7+
const undefinedField = graphQLError.errors.find((err) => err.extensions?.code === 'undefinedField')
8+
if (undefinedField && undefinedField.extensions?.fieldName.includes('bulkDataStore')) {
9+
return true
10+
}
11+
}
12+
}
13+
return false
14+
}

0 commit comments

Comments
 (0)