Skip to content

Commit 13e54c7

Browse files
authored
Merge pull request #6572 from Shopify/11-04-fix_loader_error_for_local_mode
Fix loader error for local mode
2 parents 7a4bf98 + c8d8e33 commit 13e54c7

File tree

2 files changed

+67
-5
lines changed

2 files changed

+67
-5
lines changed

packages/app/src/cli/models/app/loader.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,66 @@ redirect_urls = [ "https://example.com/api/auth" ]
527527
expect(app.errors).toBeUndefined()
528528
})
529529

530+
test('throws error for duplicated handles when mode is local', async () => {
531+
// Given
532+
await writeConfig(appConfiguration)
533+
534+
const blockConfiguration = `
535+
api_version = "2022-07"
536+
537+
[[extensions]]
538+
type = "checkout_post_purchase"
539+
name = "my_extension_1"
540+
handle = "handle-1"
541+
description = "custom description"
542+
543+
[[extensions]]
544+
type = "flow_action"
545+
handle = "handle-1"
546+
name = "my_extension_1_flow"
547+
description = "custom description"
548+
runtime_url = "https://example.com"
549+
`
550+
await writeBlockConfig({
551+
blockConfiguration,
552+
name: 'my_extension_1',
553+
})
554+
await writeFile(joinPath(blockPath('my_extension_1'), 'index.js'), '')
555+
556+
// When/Then
557+
await expect(loadTestingApp({mode: 'local'})).rejects.toThrow(/Duplicated handle/)
558+
})
559+
560+
test('does not throw error for duplicated handles when mode is report', async () => {
561+
// Given
562+
await writeConfig(appConfiguration)
563+
564+
const blockConfiguration = `
565+
api_version = "2022-07"
566+
567+
[[extensions]]
568+
type = "checkout_post_purchase"
569+
name = "my_extension_1"
570+
handle = "handle-1"
571+
description = "custom description"
572+
573+
[[extensions]]
574+
type = "flow_action"
575+
handle = "handle-1"
576+
name = "my_extension_1_flow"
577+
description = "custom description"
578+
runtime_url = "https://example.com"
579+
`
580+
await writeBlockConfig({
581+
blockConfiguration,
582+
name: 'my_extension_1',
583+
})
584+
await writeFile(joinPath(blockPath('my_extension_1'), 'index.js'), '')
585+
586+
// When/Then
587+
await expect(loadTestingApp({mode: 'report'})).resolves.not.toThrow()
588+
})
589+
530590
test('throws if 2 or more extensions have the same handle', async () => {
531591
// Given
532592
await writeConfig(appConfiguration)

packages/app/src/cli/models/app/loader.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -739,11 +739,13 @@ class AppLoader<TConfig extends AppConfiguration, TModuleSpec extends ExtensionS
739739
}
740740

741741
private abortOrReport<T>(errorMessage: OutputMessage, fallback: T, configurationPath: string): T {
742-
if (this.mode === 'strict') {
743-
throw new AbortError(errorMessage)
744-
} else {
745-
this.errors.addError(configurationPath, errorMessage)
746-
return fallback
742+
switch (this.mode) {
743+
case 'strict':
744+
case 'local':
745+
throw new AbortError(errorMessage)
746+
case 'report':
747+
this.errors.addError(configurationPath, errorMessage)
748+
return fallback
747749
}
748750
}
749751

0 commit comments

Comments
 (0)