Skip to content

Commit 6bb6235

Browse files
authored
[FIX] Bundler: Improve error log messages (#466)
1 parent 18f0df8 commit 6bb6235

File tree

5 files changed

+75
-19
lines changed

5 files changed

+75
-19
lines changed

lib/lbt/analyzer/SmartTemplateAnalyzer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class TemplateComponentAnalyzer {
6363
log.verbose("No manifest found for '%s', skipping analysis", resource.name);
6464
}
6565
} catch (err) {
66-
log.error("an error occurred while analyzing template app %s (ignored)", resource.name, err);
66+
log.error("an error occurred while analyzing template app %s (ignored):", resource.name);
67+
log.error(err.stack);
6768
}
6869

6970
return info;

lib/lbt/analyzer/XMLTemplateAnalyzer.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,16 +323,21 @@ class XMLTemplateAnalyzer {
323323
// represent an expression binding which needs to be evaluated before analysis
324324
// e.g. "{= '{Handler: \'' + ${myActions > handlerModule} + '\'}'}"
325325
if ((coreRequire.startsWith("{=") || coreRequire.startsWith("{:=")) && this.templateTag) {
326-
log.verbose(`Ignoring core:require: Attribute of Node ${node.$ns.local} contains an expression binding and is within a 'template' Node`);
327-
log.verbose(coreRequire);
326+
log.verbose(
327+
`Ignoring core:require: '%s' on Node %s:%s contains ` +
328+
`an expression binding and is within a 'template' Node`,
329+
coreRequire, node.$ns.uri, node.$ns.local
330+
);
328331
return;
329332
}
330333

331334
try {
332335
requireContext = JSTokenizer.parseJS(coreRequire);
333336
} catch (e) {
334-
log.error("Ignoring core:require: Attribute can't be parsed on Node ", node.$ns.local);
335-
log.error(coreRequire);
337+
log.error(
338+
"Ignoring core:require: '%s' can't be parsed on Node %s:%s",
339+
coreRequire, node.$ns.uri, node.$ns.local
340+
);
336341
}
337342
if ( requireContext ) {
338343
Object.keys(requireContext).forEach((key) => {

lib/lbt/bundle/Builder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ function rewriteDefine(targetBundleFormat, code, moduleName, avoidLazyParsing) {
506506
try {
507507
ast = esprima.parseScript(code.toString(), {loc: true});
508508
} catch (e) {
509-
log.error("error while parsing %s:%s", module, e);
509+
log.error("error while parsing %s: %s", moduleName, e.message);
510510
return;
511511
}
512512

lib/lbt/resources/ResourcePool.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,19 @@ async function determineDependencyInfo(resource, rawInfo, pool) {
6565
const code = await resource.buffer();
6666
info.size = code.length;
6767
const promises = [];
68+
let ast;
6869
try {
69-
const ast = esprima.parseScript(code.toString(), {comment: true});
70-
jsAnalyzer.analyze(ast, resource.name, info);
71-
new XMLCompositeAnalyzer(pool).analyze(ast, resource.name, info);
72-
} catch (error) {
73-
log.error("failed to parse or analyze %s:", resource.name, error);
70+
ast = esprima.parseScript(code.toString(), {comment: true});
71+
} catch (err) {
72+
log.error("failed to parse %s: %s", resource.name, err.message);
73+
}
74+
if (ast) {
75+
try {
76+
jsAnalyzer.analyze(ast, resource.name, info);
77+
new XMLCompositeAnalyzer(pool).analyze(ast, resource.name, info);
78+
} catch (error) {
79+
log.error("failed to analyze %s: %s", resource.name, error.stack);
80+
}
7481
}
7582
if ( rawInfo ) {
7683
info.rawModule = true;

test/lib/lbt/analyzer/XMLTemplateAnalyzer.js

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test.serial("integration: Analysis of an xml view with core:require from databin
8585
</HBox>
8686
<HBox>
8787
<Button
88-
core:require="{= '{Handler: \\'' + \${myActions > handlerModule} + '\\'}'}"
88+
core:require="{= '{Handler: \\'' + \${myActions>handlerModule} + '\\'}'}"
8989
id="myID"
9090
text="{myAction>text}"
9191
press="myMethod"
@@ -107,9 +107,13 @@ test.serial("integration: Analysis of an xml view with core:require from databin
107107
t.true(moduleInfo.isImplicitDependency("sap/ui/core/mvc/XMLView.js"),
108108
"Implicit dependency should be added since an XMLView is analyzed");
109109

110-
t.is(errorLogStub.callCount, 2, "should be called 2 times");
111-
t.is(errorLogStub.getCall(0).args[0], "Ignoring core:require: Attribute can't be parsed on Node ", "first argument");
112-
t.is(errorLogStub.getCall(0).args[1], "Button", "second argument");
110+
t.is(errorLogStub.callCount, 1, "should be called 1 time");
111+
t.deepEqual(errorLogStub.getCall(0).args, [
112+
"Ignoring core:require: '%s' can't be parsed on Node %s:%s",
113+
"{= '{Handler: \\'' + ${myActions>handlerModule} + '\\'}'}",
114+
"sap.m",
115+
"Button"
116+
], "should be called with expected args");
113117
});
114118

115119
test.serial("integration: Analysis of an xml view with core:require from databinding in template", async (t) => {
@@ -153,8 +157,13 @@ test.serial("integration: Analysis of an xml view with core:require from databin
153157
t.true(moduleInfo.isImplicitDependency("sap/ui/core/mvc/XMLView.js"),
154158
"Implicit dependency should be added since an XMLView is analyzed");
155159

156-
t.is(verboseLogStub.callCount, 2, "should be called 2 times");
157-
t.is(verboseLogStub.getCall(0).args[0], "Ignoring core:require: Attribute of Node Button contains an expression binding and is within a 'template' Node", "first argument");
160+
t.is(verboseLogStub.callCount, 1, "should be called 1 time");
161+
t.deepEqual(verboseLogStub.getCall(0).args, [
162+
"Ignoring core:require: '%s' on Node %s:%s contains an expression binding and is within a 'template' Node",
163+
"{= '{Handler: \\'' + ${myActions > handlerModule} + '\\'}'}",
164+
"sap.m",
165+
"Button"
166+
], "should be called with expected args");
158167
});
159168

160169
test.serial("integration: Analysis of an xml view with core:require from expression binding in template", async (t) => {
@@ -194,8 +203,13 @@ test.serial("integration: Analysis of an xml view with core:require from express
194203
t.true(moduleInfo.isImplicitDependency("sap/ui/core/mvc/XMLView.js"),
195204
"Implicit dependency should be added since an XMLView is analyzed");
196205

197-
t.is(verboseLogStub.callCount, 2, "should be called 2 times");
198-
t.is(verboseLogStub.getCall(0).args[0], "Ignoring core:require: Attribute of Node Button contains an expression binding and is within a 'template' Node", "first argument");
206+
t.is(verboseLogStub.callCount, 1, "should be called 1 time");
207+
t.deepEqual(verboseLogStub.getCall(0).args, [
208+
"Ignoring core:require: '%s' on Node %s:%s contains an expression binding and is within a 'template' Node",
209+
"{= 'foo': true}",
210+
"sap.m",
211+
"Button"
212+
], "should be called with expected args");
199213
});
200214

201215
test("integration: Analysis of an xml view with core:require", async (t) => {
@@ -447,3 +461,32 @@ test("_analyzeViewRootNode: process node", async (t) => {
447461
t.deepEqual(stubAddDependency.getCall(1).args[0], "myResourceBundleName.properties",
448462
"addDependency should be called with the dependency name");
449463
});
464+
465+
test("_analyzeCoreRequire: Catches error when attribute can't be parsed", async (t) => {
466+
const analyzer = new XMLTemplateAnalyzer();
467+
analyzer.info = {
468+
addImplicitDependency: function() {},
469+
addDependency: function() {}
470+
};
471+
const stubAddImplicitDependency = sinon.spy(analyzer.info, "addImplicitDependency");
472+
const stubAddDependency = sinon.spy(analyzer.info, "addDependency");
473+
474+
const node = {
475+
$: {
476+
"core:require": {
477+
name: "core:require",
478+
prefix: "core",
479+
local: "require",
480+
uri: "sap.ui.core",
481+
value: "{= '{Handler: \\'' + ${action>handlerModule} + '\\'}'}"
482+
}
483+
},
484+
$ns: {
485+
local: "Button"
486+
}
487+
};
488+
await analyzer._analyzeCoreRequire(node);
489+
490+
t.is(stubAddImplicitDependency.callCount, 0, "addImplicitDependency was never called");
491+
t.is(stubAddDependency.callCount, 0, "addDependency was never called");
492+
});

0 commit comments

Comments
 (0)