Skip to content

Commit 16a4e78

Browse files
committed
[FIX] manifestEnhancer: Improve error handling
1 parent 421a375 commit 16a4e78

File tree

2 files changed

+100
-2
lines changed

2 files changed

+100
-2
lines changed

lib/processors/manifestEnhancer.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ class ManifestEnhancer {
359359
this.runInvoked = true;
360360

361361
if (!this.manifest._version) {
362-
log.verbose(`${this.filePath}: _version is not defined. No supportedLocales are generated`);
362+
log.verbose(`${this.filePath}: _version is not defined. No supportedLocales can be generated`);
363363
return;
364364
}
365365

@@ -368,6 +368,11 @@ class ManifestEnhancer {
368368
return;
369369
}
370370

371+
if (!this.manifest["sap.app"]?.id) {
372+
log.verbose(`${this.filePath}: sap.app/id is not defined. No supportedLocales can be generated`);
373+
return;
374+
}
375+
371376
if (this.manifest["sap.app"].type === "library") {
372377
await this.processSapUi5LibraryI18n();
373378
} else {

test/lib/processors/manifestEnhancer.js

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,33 @@ test("Application: No replacement (No properties files)", async (t) => {
7979
t.true(t.context.logErrorSpy.notCalled, "No errors should be logged");
8080
});
8181

82+
test("Application: Missing sap.app/id", async (t) => {
83+
const {manifestEnhancer, fs, createResource} = t.context;
84+
85+
const input = JSON.stringify({
86+
"_version": "1.58.0",
87+
"sap.app": {
88+
"type": "application"
89+
}
90+
}, null, 2);
91+
92+
const resource = createResource("/resources/sap/ui/demo/app/manifest.json", true, input);
93+
94+
const processedResources = await manifestEnhancer({
95+
resources: [resource],
96+
fs
97+
});
98+
99+
t.deepEqual(processedResources, [], "Only enhanced resources are returned");
100+
101+
t.is(resource.setString.callCount, 0, "setString should not be called");
102+
103+
t.is(t.context.logVerboseSpy.callCount, 1, "One verbose messages should be logged");
104+
t.is(t.context.logVerboseSpy.getCall(0).args[0],
105+
"/resources/sap/ui/demo/app/manifest.json: sap.app/id is not defined. No supportedLocales can be generated");
106+
t.true(t.context.logWarnSpy.notCalled, "No warnings should be logged");
107+
t.true(t.context.logErrorSpy.notCalled, "No errors should be logged");
108+
});
82109

83110
test("Application: sap.app/i18n (without templates, default bundle): " +
84111
"Adds supportedLocales based on available properties files",
@@ -1115,7 +1142,7 @@ test("Application: sap.ui5/models: Log verbose if manifest version is not define
11151142

11161143
t.is(t.context.logVerboseSpy.callCount, 1, "1 verbose should be logged");
11171144
t.is(t.context.logVerboseSpy.getCall(0).args[0],
1118-
"/resources/sap/ui/demo/app/manifest.json: _version is not defined. No supportedLocales are generated");
1145+
"/resources/sap/ui/demo/app/manifest.json: _version is not defined. No supportedLocales can be generated");
11191146
t.true(t.context.logWarnSpy.notCalled, "No warning should be logged");
11201147
t.true(t.context.logErrorSpy.notCalled, "No errors should be logged");
11211148
t.is(fs.readdir.callCount, 0, "readdir should not be called because _version is not defined");
@@ -1722,6 +1749,72 @@ test("Library: No replacement at all", async (t) => {
17221749
t.true(t.context.logErrorSpy.notCalled, "No errors should be logged");
17231750
});
17241751

1752+
test("Library: Missing sap.app section", async (t) => {
1753+
const {manifestEnhancer, fs, createResource} = t.context;
1754+
const input = JSON.stringify({
1755+
"_version": "1.58.0",
1756+
"sap.ui5": {
1757+
"library": {
1758+
"i18n": {
1759+
"bundleUrl": "i18n.properties"
1760+
}
1761+
}
1762+
}
1763+
}, null, 2);
1764+
1765+
const resource = createResource("/resources/sap/ui/demo/lib/manifest.json", true, input);
1766+
1767+
const processedResources = await manifestEnhancer({
1768+
resources: [resource],
1769+
fs
1770+
});
1771+
1772+
t.deepEqual(processedResources, [], "Only enhanced resources are returned");
1773+
1774+
t.is(resource.setString.callCount, 0, "setString should not be called");
1775+
1776+
t.is(t.context.logVerboseSpy.callCount, 1, "One verbose messages should be logged");
1777+
t.is(t.context.logVerboseSpy.getCall(0).args[0],
1778+
"/resources/sap/ui/demo/lib/manifest.json: sap.app/id is not defined. No supportedLocales can be generated");
1779+
t.true(t.context.logWarnSpy.notCalled, "No warnings should be logged");
1780+
t.true(t.context.logErrorSpy.notCalled, "No errors should be logged");
1781+
});
1782+
1783+
test("Library: Missing sap.app/id", async (t) => {
1784+
const {manifestEnhancer, fs, createResource} = t.context;
1785+
1786+
const input = JSON.stringify({
1787+
"_version": "1.58.0",
1788+
"sap.app": {
1789+
"type": "library"
1790+
},
1791+
"sap.ui5": {
1792+
"library": {
1793+
"i18n": {
1794+
"bundleUrl": "i18n.properties"
1795+
}
1796+
}
1797+
}
1798+
}, null, 2);
1799+
1800+
const resource = createResource("/resources/sap/ui/demo/lib/manifest.json", true, input);
1801+
1802+
const processedResources = await manifestEnhancer({
1803+
resources: [resource],
1804+
fs
1805+
});
1806+
1807+
t.deepEqual(processedResources, [], "Only enhanced resources are returned");
1808+
1809+
t.is(resource.setString.callCount, 0, "setString should not be called");
1810+
1811+
t.is(t.context.logVerboseSpy.callCount, 1, "One verbose messages should be logged");
1812+
t.is(t.context.logVerboseSpy.getCall(0).args[0],
1813+
"/resources/sap/ui/demo/lib/manifest.json: sap.app/id is not defined. No supportedLocales can be generated");
1814+
t.true(t.context.logWarnSpy.notCalled, "No warnings should be logged");
1815+
t.true(t.context.logErrorSpy.notCalled, "No errors should be logged");
1816+
});
1817+
17251818
test("Library: sap.app/i18n (with templates, no bundle defined): " +
17261819
"Does not add supportedLocales, as sap.app/i18n is not valid for libraries",
17271820
async (t) => {

0 commit comments

Comments
 (0)