Skip to content

Commit 0ee1e1e

Browse files
committed
[pbxProject] throw parser errors correctly
1 parent aa3236c commit 0ee1e1e

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

lib/pbxProject.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@ pbxProject.prototype.parse = function (cb) {
2121
var worker = fork(__dirname + '/parseJob.js', [this.filepath])
2222

2323
worker.on('message', function (msg) {
24-
if (msg.code) {
24+
if (msg.name == 'SyntaxError' || msg.code) {
2525
this.emit('error', msg);
2626
} else {
2727
this.hash = msg;
2828
this.emit('end', null, msg)
2929
}
3030
}.bind(this));
3131

32-
if (cb)
32+
if (cb) {
33+
this.on('error', cb);
3334
this.on('end', cb);
35+
}
3436

3537
return this;
3638
}

test/parser/projects/fail.pbxproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// !$*UTF8*$!
2+
THIS SHOULD FAIL TO PARSE
3+
{
4+
archiveVersion = 1;
5+
classes = {
6+
};
7+
objectVersion = 45;
8+
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
9+
objects = {
10+
/* Begin PBXTargetDependency section */
11+
301BF551109A68C00062928A /* PBXTargetDependency */ = {
12+
isa = PBXTargetDependency;
13+
name = PhoneGapLib;
14+
targetProxy = 301BF550109A68C00062928A /* PBXContainerItemProxy */;
15+
};
16+
/* End PBXTargetDependency section */
17+
};
18+
}

test/pbxProject.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ exports['parse function'] = {
5555
test.ok(myProj.hash);
5656
test.done();
5757
})
58+
},
59+
'it should pass an error object back when the parsing fails': function (test) {
60+
var myProj = new pbx('test/parser/projects/fail.pbxproj');
61+
62+
myProj.parse(function (err, projHash) {
63+
test.ok(err);
64+
test.done();
65+
})
5866
}
5967
}
6068

0 commit comments

Comments
 (0)