Skip to content

Commit 2a9d433

Browse files
authored
Merge pull request #4758 from NativeScript/kddimitrov/fix-log-split
Kddimitrov/fix log split
2 parents e1ac117 + 43058f6 commit 2a9d433

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

lib/services/log-source-map-service.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ interface IParsedMessage {
99
filePath?: string;
1010
line?: number;
1111
column?: number;
12-
message: string;
12+
messagePrefix: string;
13+
messageSuffix: string;
1314
}
1415

1516
interface IFileLocation {
@@ -46,7 +47,7 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
4647

4748
if (originalLocation && originalLocation.sourceFile) {
4849
const {sourceFile, line, column} = originalLocation;
49-
outputData = `${outputData}${parsedLine.message} ${LogSourceMapService.FILE_PREFIX}${sourceFile}:${line}:${column}\n`;
50+
outputData = `${outputData}${parsedLine.messagePrefix}${LogSourceMapService.FILE_PREFIX}${sourceFile}:${line}:${column}${parsedLine.messageSuffix}\n`;
5051
} else if (rawLine !== "") {
5152
outputData = `${outputData}${rawLine}\n`;
5253
}
@@ -85,13 +86,14 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
8586
// "System.err: File: "file:///data/data/org.nativescript.sourceMap/files/app/bundle.js, line: 304, column: 8"
8687
const fileIndex = rawMessage.lastIndexOf(LogSourceMapService.FILE_PREFIX);
8788
const deviceProjectPath = util.format(ANDROID_DEVICE_APP_ROOT_TEMPLATE, projectData.projectIdentifiers.android);
88-
let message = rawMessage;
89-
let parts, filePath, line, column;
89+
let separator = ",";
90+
let messageSuffix = "";
91+
let parts, filePath, line, column, messagePrefix;
9092

9193
if (fileIndex >= 0) {
9294
const fileSubstring = rawMessage.substring(fileIndex + LogSourceMapService.FILE_PREFIX.length);
9395
//"data/data/org.nativescript.sourceMap/files/app/bundle.js, line: 304, column: 8"
94-
parts = fileSubstring.split(",");
96+
parts = fileSubstring.split(separator);
9597
if (parts.length >= 3) {
9698
// "data/data/org.nativescript.sourceMap/files/app/bundle.js"
9799
parts[0] = parts[0].replace("'", "");
@@ -101,7 +103,8 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
101103
parts[2] = parts[2].replace(" column: ", "");
102104
} else {
103105
// "data/data/org.nativescript.sourceMap/files/app/bundle.js:303:17)"
104-
parts = fileSubstring.split(":");
106+
separator = ":";
107+
parts = fileSubstring.split(separator);
105108
}
106109

107110
if (parts.length >= 3) {
@@ -111,24 +114,23 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
111114
filePath = path.relative(devicePath, `${"/"}${parts[0]}`);
112115
line = parseInt(parts[1]);
113116
column = parseInt(parts[2]);
114-
message = rawMessage.substring(0, fileIndex);
117+
messagePrefix = rawMessage.substring(0, fileIndex);
115118
for (let i = 3; i < parts.length; i++) {
116-
message += parts[i];
119+
messageSuffix += `${parts[i]}${i === (parts.length - 1) ? "" : separator}`;
117120
}
118121
// "JS: at module.exports.push../main-view-model.ts.HelloWorldModel.onTap ("
119-
message = _.trimEnd(message, "(");
120-
message = message.trim();
122+
messagePrefix = _.trimEnd(messagePrefix, "(");
121123
}
122124
}
123125

124-
return { filePath, line, column, message };
126+
return { filePath, line, column, messagePrefix, messageSuffix};
125127
}
126128

127129
private parseIosLog(rawMessage: string): IParsedMessage {
128130
// "CONSOLE INFO file:///app/vendor.js:131:36: HMR: Hot Module Replacement Enabled. Waiting for signal."
129131
const fileIndex = rawMessage.lastIndexOf(LogSourceMapService.FILE_PREFIX);
130-
let message = rawMessage;
131-
let parts, filePath, line, column;
132+
let messageSuffix = "";
133+
let parts, filePath, line, column, messagePrefix;
132134

133135
if (fileIndex >= 0) {
134136
// "app/vendor.js:131:36: HMR: Hot Module Replacement Enabled. Waiting for signal."
@@ -144,15 +146,14 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
144146
line = parseInt(parts[1]);
145147
column = parseInt(parts[2]);
146148

147-
message = rawMessage.substring(0, fileIndex).trim();
149+
messagePrefix = rawMessage.substring(0, fileIndex);
148150
for (let i = 3; i < parts.length; i++) {
149-
message += parts[i];
151+
messageSuffix += `${parts[i]}${i === (parts.length - 1) ? "" : ":"}`;
150152
}
151-
message = message.trim();
152153
}
153154
}
154155

155-
return { filePath, line, column, message };
156+
return { filePath, line, column, messagePrefix, messageSuffix };
156157
}
157158

158159
private getFilesLocation(platform: string, projectData: IProjectData): string {

test/services/log-source-map-service.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const testCases: IDictionary<Array<{caseName: string, message: string, expected:
4747
}, {
4848
caseName: "error message",
4949
message: "System.err: Frame: function:'module.exports.push../main-view-model.ts.HelloWorldModel.onTap', file:'file:///data/data/org.nativescript.sourceMap/files/app/bundle.js', line: 304, column: 15",
50-
expected: `System.err: Frame: function:'module.exports.push../main-view-model.ts.HelloWorldModel.onTap', file:' file:///${toPlatformSep("src/main-view-model.ts")}:31:14\n`
50+
expected: `System.err: Frame: function:'module.exports.push../main-view-model.ts.HelloWorldModel.onTap', file:'file:///${toPlatformSep("src/main-view-model.ts")}:31:14\n`
5151
}, {
5252
caseName: "error message no match",
5353
message: "System.err: Frame: function:'module.exports.push../main-view-model.ts.HelloWorldModel.onTap', file:'file:///data/data/org.nativescript.sourceMap/files/app/bundle.js', line: 400, column: 15",
@@ -60,15 +60,19 @@ const testCases: IDictionary<Array<{caseName: string, message: string, expected:
6060
"ios": [{
6161
caseName: "console message",
6262
message: "CONSOLE LOG file:///app/bundle.js:294:20: Test.",
63-
expected: `CONSOLE LOG Test. file:///${toPlatformSep("src/main-view-model.ts")}:29:20\n`
63+
expected: `CONSOLE LOG file:///${toPlatformSep("src/main-view-model.ts")}:29:20 Test.\n`
6464
}, {
6565
caseName: "trace message",
6666
message: "CONSOLE TRACE file:///app/bundle.js:295:22: Test",
67-
expected: `CONSOLE TRACE Test file:///${toPlatformSep("src/main-view-model.ts")}:30:22\n`
67+
expected: `CONSOLE TRACE file:///${toPlatformSep("src/main-view-model.ts")}:30:22 Test\n`
6868
}, {
6969
caseName: "error message",
7070
message: "file:///app/bundle.js:296:32: JS ERROR Error: Test",
71-
expected: `JS ERROR Error Test file:///${toPlatformSep("src/main-view-model.ts")}:31:31\n`
71+
expected: `file:///${toPlatformSep("src/main-view-model.ts")}:31:31 JS ERROR Error: Test\n`
72+
}, {
73+
caseName: "error stack tracew",
74+
message: "onTap@file:///app/bundle.js:296:32",
75+
expected: `onTap@file:///${toPlatformSep("src/main-view-model.ts")}:31:31\n`
7276
}, {
7377
caseName: "error message no match",
7478
message: "file:///app/bundle.js:400:32: JS ERROR Error: Test",

0 commit comments

Comments
 (0)