Skip to content

Commit 39a47e2

Browse files
authored
Merge pull request #6529 from Shopify/10-17-improve_error_message_when_multiple_web_configs_are_found
Improve error message when multiple web configs are found
2 parents 7a0d206 + e556d7a commit 39a47e2

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,18 @@ wrong = "property"
578578
await writeWebConfiguration({webDirectory: anotherWebDirectory, role: 'backend'})
579579

580580
// Then
581-
await expect(loadTestingApp()).rejects.toThrow()
581+
try {
582+
await loadTestingApp()
583+
expect.fail('Expected loadTestingApp to throw an error')
584+
} catch (error) {
585+
if (!(error instanceof AbortError)) {
586+
throw error
587+
}
588+
expect(error.message).toContain('You can only have one "web" configuration file with the backend role')
589+
expect(error.message).toContain('Conflicting configurations found at:')
590+
expect(error.message).toContain(joinPath(webDirectory, configurationFileNames.web))
591+
expect(error.message).toContain(joinPath(anotherWebDirectory, configurationFileNames.web))
592+
}
582593
})
583594

584595
test('throws an error if there are multiple frontends', async () => {
@@ -590,7 +601,18 @@ wrong = "property"
590601
await writeWebConfiguration({webDirectory: anotherWebDirectory, role: 'frontend'})
591602

592603
// Then
593-
await expect(loadTestingApp()).rejects.toThrow()
604+
try {
605+
await loadTestingApp()
606+
expect.fail('Expected loadTestingApp to throw an error')
607+
} catch (error) {
608+
if (!(error instanceof AbortError)) {
609+
throw error
610+
}
611+
expect(error.message).toContain('You can only have one "web" configuration file with the frontend role')
612+
expect(error.message).toContain('Conflicting configurations found at:')
613+
expect(error.message).toContain(joinPath(webDirectory, configurationFileNames.web))
614+
expect(error.message).toContain(joinPath(anotherWebDirectory, configurationFileNames.web))
615+
}
594616
})
595617

596618
test('loads the app with custom located web blocks', async () => {

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,12 +428,17 @@ class AppLoader<TConfig extends AppConfiguration, TModuleSpec extends ExtensionS
428428
private validateWebs(webs: Web[]): void {
429429
;[WebType.Backend, WebType.Frontend].forEach((webType) => {
430430
const websOfType = webs.filter((web) => web.configuration.roles.includes(webType))
431-
if (websOfType[1]) {
431+
if (websOfType.length > 1) {
432+
const conflictingPaths = websOfType.map((web) => joinPath(web.directory, configurationFileNames.web))
433+
const pathsList = conflictingPaths.map((path) => ` ${path}`).join('\n')
434+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
435+
const lastConflictingPath = conflictingPaths[conflictingPaths.length - 1]!
432436
this.abortOrReport(
433-
outputContent`You can only have one web with the ${outputToken.yellow(webType)} role in your app`,
437+
outputContent`You can only have one "web" configuration file with the ${outputToken.yellow(
438+
webType,
439+
)} role in your app.\n\nConflicting configurations found at:\n${pathsList}`,
434440
undefined,
435-
436-
joinPath(websOfType[1].directory, configurationFileNames.web),
441+
lastConflictingPath,
437442
)
438443
}
439444
})

0 commit comments

Comments
 (0)