@@ -3,6 +3,8 @@ import {validateApp} from '../../../services/validate.js'
33import AppLinkedCommand , { AppLinkedCommandOutput } from '../../../utilities/app-linked-command.js'
44import { linkedAppContext } from '../../../services/app-context.js'
55import { globalFlags , jsonFlag } from '@shopify/cli-kit/node/cli'
6+ import { AbortError , AbortSilentError } from '@shopify/cli-kit/node/error'
7+ import { outputResult , stringifyMessage , unstyled } from '@shopify/cli-kit/node/output'
68
79export default class Validate extends AppLinkedCommand {
810 static summary = 'Validate your app configuration and extensions.'
@@ -20,13 +22,24 @@ export default class Validate extends AppLinkedCommand {
2022 public async run ( ) : Promise < AppLinkedCommandOutput > {
2123 const { flags} = await this . parse ( Validate )
2224
23- const { app} = await linkedAppContext ( {
24- directory : flags . path ,
25- clientId : flags [ 'client-id' ] ,
26- forceRelink : flags . reset ,
27- userProvidedConfigName : flags . config ,
28- unsafeTolerateErrors : true ,
29- } )
25+ let app
26+ try {
27+ const context = await linkedAppContext ( {
28+ directory : flags . path ,
29+ clientId : flags [ 'client-id' ] ,
30+ forceRelink : flags . reset ,
31+ userProvidedConfigName : flags . config ,
32+ unsafeTolerateErrors : true ,
33+ } )
34+ app = context . app
35+ } catch ( err ) {
36+ if ( err instanceof AbortError && flags . json ) {
37+ const message = unstyled ( stringifyMessage ( err . message ) ) . trim ( )
38+ outputResult ( JSON . stringify ( { valid : false , errors : [ { message} ] } , null , 2 ) )
39+ throw new AbortSilentError ( )
40+ }
41+ throw err
42+ }
3043
3144 await validateApp ( app , { json : flags . json } )
3245
0 commit comments