Skip to content

Commit f4a87f9

Browse files
author
Tsvetan Raikov
committed
Fixed tns device log throws exception
1 parent d29bc36 commit f4a87f9

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

lib/services/ios-log-filter.ts

+26-16
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import * as path from "path";
33

44
export class IOSLogFilter implements Mobile.IPlatformLogFilter {
55

6+
private $projectData: IProjectData;
7+
68
constructor(
79
private $fs: IFileSystem,
8-
private $projectData: IProjectData,
910
private $loggingLevels: Mobile.ILoggingLevels) { }
1011

1112
public filterData(data: string, logLevel: string, pid?: string): string {
@@ -22,8 +23,8 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
2223
}
2324
// CONSOLE LOG messages comme in the following form:
2425
// <date> <domain> <app>[pid] CONSOLE LOG file:///location:row:column: <actual message goes here>
25-
// This code removes unnecessary information from log messages. The output looks like:
26-
// CONSOLE LOG file:///location:row:column: <actual message goes here>
26+
// This code removes unnecessary information from log messages. The output looks like:
27+
// CONSOLE LOG file:///location:row:column: <actual message goes here>
2728
if (pid) {
2829
let searchString = "["+pid+"]: ";
2930
let pidIndex = data.indexOf(searchString);
@@ -45,24 +46,33 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
4546
let parts = data.substring(fileIndex + fileString.length).split(":");
4647
if (parts.length >= 4) {
4748
let file = parts[0];
48-
let sourceMapFile = path.join(this.$projectData.projectDir, file + ".map");
49-
let row = parseInt(parts[1]);
50-
let column = parseInt(parts[2]);
51-
if (this.$fs.exists(sourceMapFile).wait()) {
52-
let sourceMap = this.$fs.readText(sourceMapFile, "utf8").wait();
53-
let smc = new sourcemap.SourceMapConsumer(sourceMap);
54-
let originalPosition = smc.originalPositionFor({line:row,column:column});
55-
data = data.substring(0, fileIndex + fileString.length)
56-
+ file.replace(".js", ".ts") + ":"
57-
+ originalPosition.line + ":"
58-
+ originalPosition.column;
59-
for (let i = 3; i<parts.length; i++) {
60-
data += ":" + parts[i];
49+
if (this.ensureProjectData()) {
50+
let sourceMapFile = path.join(this.$projectData.projectDir, file + ".map");
51+
let row = parseInt(parts[1]);
52+
let column = parseInt(parts[2]);
53+
if (this.$fs.exists(sourceMapFile).wait()) {
54+
let sourceMap = this.$fs.readText(sourceMapFile, "utf8").wait();
55+
let smc = new sourcemap.SourceMapConsumer(sourceMap);
56+
let originalPosition = smc.originalPositionFor({line:row,column:column});
57+
data = data.substring(0, fileIndex + fileString.length)
58+
+ file.replace(".js", ".ts") + ":"
59+
+ originalPosition.line + ":"
60+
+ originalPosition.column;
61+
for (let i = 3; i<parts.length; i++) {
62+
data += ":" + parts[i];
63+
}
6164
}
6265
}
6366
}
6467
}
6568
return data;
6669
}
70+
71+
private ensureProjectData(): boolean {
72+
if (!this.$projectData) {
73+
this.$projectData = $injector.resolve("projectData");
74+
}
75+
return !!this.$projectData;
76+
}
6777
}
6878
$injector.register("iOSLogFilter", IOSLogFilter);

0 commit comments

Comments
 (0)