Permalink
Browse files

Merge pull request #1646 from ajaxorg/revisions_better_parse

Revisions better parse
  • Loading branch information...
zefhemel committed Jun 4, 2012
2 parents ef4174d + 5d1af0a commit 01838740a9e05aa0c901fad74ad9151c168baefa
Showing with 29 additions and 13 deletions.
  1. +29 −13 plugins-server/cloud9.ide.revisions/revisions.js
@@ -108,6 +108,10 @@ require("util").inherits(RevisionsPlugin, Plugin);
self.broadcastConfirmSave(message.path, revisionInfo.revision);
if (message.forceRevisionListResponse === true) {
self.getAllRevisions(revisionInfo.absPath, function(err, revObj) {
+ if (err) {
+ return console.error(err);
+ }
+
self.broadcastRevisions.call(self, revObj, user, {
path: message.path
});
@@ -117,7 +121,8 @@ require("util").inherits(RevisionsPlugin, Plugin);
else {
this.getRevisions(message.path, function(err, revObj) {
if (err) {
- return console.error("There was a problem retrieving the revisions" + " for the file " + message.path + ":\n", err);
+ return console.error("There was a problem retrieving revisions" +
+ " for the file " + message.path + ":\n", err);
}
self.broadcastRevisions.call(self, revObj, null, {
@@ -196,22 +201,33 @@ require("util").inherits(RevisionsPlugin, Plugin);
return callback(err);
}
+ var error;
+ var lineCount = 0;
var lines = data.toString().split("\n");
-
- Async.forEachSeries(lines,
- function(line, next) {
- try {
+ if (lines.length) {
+ Async.whilst(
+ function () {
+ return lineCount < lines.length && !error;
+ },
+ function (next) {
+ var line = lines[lineCount];
if (line) {
- var revision = JSON.parse(line);
- revObj[revision.ts] = revision;
+ try {
+ var revision = JSON.parse(line);
+ revObj[revision.ts] = revision;
+ }
+ catch(e) {
+ error = e;
+ }
}
+ lineCount++;
+ next();
+ },
+ function (e) {
+ callback(error, revObj);
}
- catch(e) {
- console.error("Revision JSON Parse error", e.message, line);
- }
- next();
- },
- function() { callback(null, revObj); });
+ );
+ }
});
};

0 comments on commit 0183874

Please sign in to comment.