diff --git a/package-lock.json b/package-lock.json index 70f3758136c..d76edc616b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@asyncapi/cli", - "version": "2.13.0", + "version": "2.14.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@asyncapi/cli", - "version": "2.13.0", + "version": "2.14.0", "license": "Apache-2.0", "dependencies": { "@asyncapi/avro-schema-parser": "^3.0.23", diff --git a/src/commands/generate/models.ts b/src/commands/generate/models.ts index 1303d442c95..5c7a04f82a2 100644 --- a/src/commands/generate/models.ts +++ b/src/commands/generate/models.ts @@ -56,19 +56,29 @@ export default class Models extends Command { const s = spinner(); s.start('Generating models...'); - const generatedModels = await generateModels({...flags, output}, document, logger, language as Languages); - if (output !== 'stdout') { - const generatedModelStrings = generatedModels.map((model) => { return model.modelName; }); - s.stop(green(`Successfully generated the following models: ${generatedModelStrings.join(', ')}`)); - return; - } - const generatedModelStrings = generatedModels.map((model) => { - return ` -## Model name: ${model.modelName} -${model.result} - `; - }); - s.stop(green(`Successfully generated the following models: ${generatedModelStrings.join('\n')}`)); + try { + const generatedModels = await generateModels({...flags, output}, document, logger, language as Languages); + if (output !== 'stdout') { + const generatedModelStrings = generatedModels.map((model) => { return model.modelName; }); + s.stop(green(`Successfully generated the following models: ${generatedModelStrings.join(', ')}`)); + return; + } + const generatedModelStrings = generatedModels.map((model) => { + return ` + ## Model name: ${model.modelName} + ${model.result} + `; + }); + s.stop(green(`Successfully generated the following models: ${generatedModelStrings.join('\n')}`)); + } catch (error) { + s.stop(green('Failed to generate models')); + + if (error instanceof Error) { + this.error(error.message); + } else { + this.error('An unknown error occurred during model generation.'); + } + } } private async parseArgs(args: Record, output?: string) {