Skip to content

Commit 43058f6

Browse files
committed
fix: restore original log message order
1 parent 70fafba commit 43058f6

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

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

Lines changed: 14 additions & 15 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,9 +86,9 @@ 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;
8989
let separator = ",";
90-
let parts, filePath, line, column;
90+
let messageSuffix = "";
91+
let parts, filePath, line, column, messagePrefix;
9192

9293
if (fileIndex >= 0) {
9394
const fileSubstring = rawMessage.substring(fileIndex + LogSourceMapService.FILE_PREFIX.length);
@@ -113,24 +114,23 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
113114
filePath = path.relative(devicePath, `${"/"}${parts[0]}`);
114115
line = parseInt(parts[1]);
115116
column = parseInt(parts[2]);
116-
message = rawMessage.substring(0, fileIndex);
117+
messagePrefix = rawMessage.substring(0, fileIndex);
117118
for (let i = 3; i < parts.length; i++) {
118-
message += `${parts[i]}${i === (parts.length - 1) ? "" : separator}`;
119+
messageSuffix += `${parts[i]}${i === (parts.length - 1) ? "" : separator}`;
119120
}
120121
// "JS: at module.exports.push../main-view-model.ts.HelloWorldModel.onTap ("
121-
message = _.trimEnd(message, "(");
122-
message = message.trim();
122+
messagePrefix = _.trimEnd(messagePrefix, "(");
123123
}
124124
}
125125

126-
return { filePath, line, column, message };
126+
return { filePath, line, column, messagePrefix, messageSuffix};
127127
}
128128

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

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

149-
message = rawMessage.substring(0, fileIndex).trim();
149+
messagePrefix = rawMessage.substring(0, fileIndex);
150150
for (let i = 3; i < parts.length; i++) {
151-
message += `${parts[i]}${i === (parts.length - 1) ? "" : ":"}`;
151+
messageSuffix += `${parts[i]}${i === (parts.length - 1) ? "" : ":"}`;
152152
}
153-
message = message.trim();
154153
}
155154
}
156155

157-
return { filePath, line, column, message };
156+
return { filePath, line, column, messagePrefix, messageSuffix };
158157
}
159158

160159
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)