Skip to content

Commit e72b30a

Browse files
authored
Merge pull request #6698 from Shopify/abort-when-no-valid-env
Abort theme command when an invalid environment is provided
2 parents b48637c + e92155e commit e72b30a

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

.changeset/fifty-plants-ask.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/theme': patch
3+
---
4+
5+
Abort theme command when an invalid environment is passed in so it doesn't fall back to cached store data

packages/theme/src/cli/utilities/theme-command.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@ describe('ThemeCommand', () => {
191191
})
192192
})
193193

194+
test('single environment provided but not found in TOML - throws AbortError', async () => {
195+
// Given
196+
vi.mocked(loadEnvironment).mockResolvedValue(undefined)
197+
198+
await CommandConfig.load()
199+
const command = new TestThemeCommand(['--environment', 'notreal'], CommandConfig)
200+
201+
// When/Then
202+
await expect(command.run()).rejects.toThrow(AbortError)
203+
await expect(command.run()).rejects.toThrow('Please provide a valid environment.')
204+
})
205+
194206
test('multiple environments provided - uses renderConcurrent for parallel execution', async () => {
195207
// Given
196208
vi.mocked(loadEnvironment)

packages/theme/src/cli/utilities/theme-command.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ export default abstract class ThemeCommand extends Command {
7979

8080
// Single environment or no environment
8181
if (environments.length <= 1) {
82+
if (environments[0] && !flags.store) {
83+
throw new AbortError(`Please provide a valid environment.`)
84+
}
85+
8286
const session = commandRequiresAuth ? await this.createSession(flags) : undefined
8387
const commandName = this.constructor.name.toLowerCase()
8488

0 commit comments

Comments
 (0)