Skip to content

Commit

Permalink
Add error handling write annotation (#2886)
Browse files Browse the repository at this point in the history
* Add error handling to fiori elements writer while generating annotations

* changeset

* test

---------

Co-authored-by: Austin Devine <[email protected]>
  • Loading branch information
kjose90 and devinea authored Feb 7, 2025
1 parent 0296d75 commit 1baff46
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-carrots-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-ux/fiori-elements-writer': patch
---

Add error handling to fiori elements writer while generating annotations
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"unsupportedOdataVersion": "OData Version of the specified service: {{ serviceVersion }}, is not supported by the template type: {{ templateType }}",
"unsupportedUI5Version": "Specified UI5 property '{{ versionProperty }}': {{ ui5Version }}, is not supported by the template type: {{ templateType }}. Please specify {{minRequiredUI5Version}} or above.",
"invalidUI5Version": "Specified UI5 property '{{ versionProperty }}': {{ ui5Version }}, is not a valid semantic version",
"missingRequiredProperty": "A property required for application generation is not specified: '{{ propertyName }}'."
"missingRequiredProperty": "A property required for application generation is not specified: '{{ propertyName }}'.",
"errorGeneratingDefaultAnnotations": "Error generating default annotations"
}
}
7 changes: 5 additions & 2 deletions packages/fiori-elements-writer/src/writeAnnotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ export async function writeAnnotations<T extends {}>(
appName: packageName,
project: projectPath
};

await generateAnnotations(fs, serviceParameters, options);
try {
await generateAnnotations(fs, serviceParameters, options);
} catch (err) {
log?.error(`${t('error.errorGeneratingDefaultAnnotations')} ${err}`);
}
} else {
log?.warn(
t('warn.invalidTypeForAnnotationGeneration', {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { join } from 'path';
import { writeAnnotations } from '../../src/writeAnnotations';
import { TemplateType } from '../../src/types';
import { OdataVersion } from '@sap-ux/odata-service-writer';
import { generateAnnotations } from '@sap-ux/annotation-generator';
import type { Editor } from 'mem-fs-editor';
import { applyBaseConfigToFEApp } from '../common';
import type { Logger } from '@sap-ux/logger';
import { t } from '../../src/i18n';

jest.mock('@sap-ux/annotation-generator', () => ({
...jest.requireActual('@sap-ux/annotation-generator'),
Expand Down Expand Up @@ -75,4 +76,16 @@ describe('writeAnnotations', () => {
}
);
});

it('should exit gracefully and log an error when generateAnnotations fails', async () => {
const log = {
error: jest.fn()
};
const appInfo = applyBaseConfigToFEApp('test', TemplateType.ListReportObjectPage);
appInfo.appOptions.addAnnotations = true;
delete appInfo.service.capService;
(generateAnnotations as jest.Mock).mockRejectedValue(new Error('test error'));
await writeAnnotations('test', appInfo, fs, log as unknown as Logger);
expect(log.error).toHaveBeenCalledWith(`${t('error.errorGeneratingDefaultAnnotations')} Error: test error`);
});
});

0 comments on commit 1baff46

Please sign in to comment.