Changed all error handling to async-stacktrace style + fixed import/export on unix

This commit is contained in:
Peter 'Pita' Martischka 2011-12-04 16:50:02 +01:00
parent db1ba6a65e
commit 5c56e62d67
18 changed files with 325 additions and 352 deletions

View file

@ -18,6 +18,7 @@
* limitations under the License. * limitations under the License.
*/ */
var ERR = require("async-stacktrace");
var padManager = require("./PadManager"); var padManager = require("./PadManager");
var padMessageHandler = require("../handler/PadMessageHandler"); var padMessageHandler = require("../handler/PadMessageHandler");
var readOnlyManager = require("./ReadOnlyManager"); var readOnlyManager = require("./ReadOnlyManager");
@ -109,11 +110,7 @@ exports.getText = function(padID, rev, callback)
//get the pad //get the pad
getPadSafe(padID, true, function(err, pad) getPadSafe(padID, true, function(err, pad)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err);
return;
}
//the client asked for a special revision //the client asked for a special revision
if(rev !== undefined) if(rev !== undefined)
@ -128,12 +125,11 @@ exports.getText = function(padID, rev, callback)
//get the text of this revision //get the text of this revision
pad.getInternalRevisionAText(rev, function(err, atext) pad.getInternalRevisionAText(rev, function(err, atext)
{ {
if(!err) if(ERR(err, callback)) return;
{
data = {text: atext.text};
}
callback(err, data); data = {text: atext.text};
callback(null, data);
}) })
} }
//the client wants the latest text, lets return it to him //the client wants the latest text, lets return it to him
@ -158,11 +154,7 @@ exports.setText = function(padID, text, callback)
//get the pad //get the pad
getPadSafe(padID, true, function(err, pad) getPadSafe(padID, true, function(err, pad)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err);
return;
}
//set the text //set the text
pad.setText(text); pad.setText(text);
@ -215,11 +207,7 @@ exports.getHTML = function(padID, rev, callback)
getPadSafe(padID, true, function(err, pad) getPadSafe(padID, true, function(err, pad)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err);
return;
}
//the client asked for a special revision //the client asked for a special revision
if(rev !== undefined) if(rev !== undefined)
@ -234,11 +222,9 @@ exports.getHTML = function(padID, rev, callback)
//get the html of this revision //get the html of this revision
exportHtml.getPadHTML(pad, rev, function(err, html) exportHtml.getPadHTML(pad, rev, function(err, html)
{ {
if(!err) if(ERR(err, callback)) return;
{ data = {html: html};
data = {html: html}; callback(null, data);
}
callback(err, data);
}); });
} }
//the client wants the latest text, lets return it to him //the client wants the latest text, lets return it to him
@ -246,11 +232,11 @@ exports.getHTML = function(padID, rev, callback)
{ {
exportHtml.getPadHTML(pad, undefined, function (err, html) exportHtml.getPadHTML(pad, undefined, function (err, html)
{ {
if(!err) if(ERR(err, callback)) return;
{
data = {html: html}; data = {html: html};
}
callback(err, data); callback(null, data);
}); });
} }
}); });
@ -261,11 +247,7 @@ exports.setHTML = function(padID, html, callback)
//get the pad //get the pad
getPadSafe(padID, true, function(err, pad) getPadSafe(padID, true, function(err, pad)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err);
return;
}
// add a new changeset with the new html to the pad // add a new changeset with the new html to the pad
importHtml.setPadHTML(pad, cleanText(html)); importHtml.setPadHTML(pad, cleanText(html));
@ -293,11 +275,7 @@ exports.getRevisionsCount = function(padID, callback)
//get the pad //get the pad
getPadSafe(padID, true, function(err, pad) getPadSafe(padID, true, function(err, pad)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err);
return;
}
callback(null, {revisions: pad.getHeadRevisionNumber()}); callback(null, {revisions: pad.getHeadRevisionNumber()});
}); });
@ -323,7 +301,8 @@ exports.createPad = function(padID, text, callback)
//create pad //create pad
getPadSafe(padID, false, text, function(err) getPadSafe(padID, false, text, function(err)
{ {
callback(err); if(ERR(err, callback)) return;
callback();
}); });
} }
@ -339,11 +318,7 @@ exports.deletePad = function(padID, callback)
{ {
getPadSafe(padID, true, function(err, pad) getPadSafe(padID, true, function(err, pad)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err);
return;
}
pad.remove(callback); pad.remove(callback);
}); });
@ -362,16 +337,13 @@ exports.getReadOnlyID = function(padID, callback)
//we don't need the pad object, but this function does all the security stuff for us //we don't need the pad object, but this function does all the security stuff for us
getPadSafe(padID, true, function(err) getPadSafe(padID, true, function(err)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err);
return;
}
//get the readonlyId //get the readonlyId
readOnlyManager.getReadOnlyId(padID, function(err, readOnlyId) readOnlyManager.getReadOnlyId(padID, function(err, readOnlyId)
{ {
callback(err, {readOnlyID: readOnlyId}); if(ERR(err, callback)) return;
callback(null, {readOnlyID: readOnlyId});
}); });
}); });
} }
@ -396,11 +368,7 @@ exports.setPublicStatus = function(padID, publicStatus, callback)
//get the pad //get the pad
getPadSafe(padID, true, function(err, pad) getPadSafe(padID, true, function(err, pad)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err);
return;
}
//convert string to boolean //convert string to boolean
if(typeof publicStatus == "string") if(typeof publicStatus == "string")
@ -433,11 +401,7 @@ exports.getPublicStatus = function(padID, callback)
//get the pad //get the pad
getPadSafe(padID, true, function(err, pad) getPadSafe(padID, true, function(err, pad)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err);
return;
}
callback(null, {publicStatus: pad.getPublicStatus()}); callback(null, {publicStatus: pad.getPublicStatus()});
}); });
@ -463,11 +427,7 @@ exports.setPassword = function(padID, password, callback)
//get the pad //get the pad
getPadSafe(padID, true, function(err, pad) getPadSafe(padID, true, function(err, pad)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err);
return;
}
//set the password //set the password
pad.setPassword(password); pad.setPassword(password);
@ -496,11 +456,7 @@ exports.isPasswordProtected = function(padID, callback)
//get the pad //get the pad
getPadSafe(padID, true, function(err, pad) getPadSafe(padID, true, function(err, pad)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err);
return;
}
callback(null, {isPasswordProtected: pad.isPasswordProtected()}); callback(null, {isPasswordProtected: pad.isPasswordProtected()});
}); });
@ -542,13 +498,10 @@ function getPadSafe(padID, shouldExist, text, callback)
//check if the pad exists //check if the pad exists
padManager.doesPadExists(padID, function(err, exists) padManager.doesPadExists(padID, function(err, exists)
{ {
//error if(ERR(err, callback)) return;
if(err)
{
callback(err);
}
//does not exist, but should //does not exist, but should
else if(exists == false && shouldExist == true) if(exists == false && shouldExist == true)
{ {
callback({stop: "padID does not exist"}); callback({stop: "padID does not exist"});
} }

View file

@ -18,6 +18,7 @@
* limitations under the License. * limitations under the License.
*/ */
var ERR = require("async-stacktrace");
var db = require("./DB").db; var db = require("./DB").db;
var async = require("async"); var async = require("async");
@ -29,7 +30,8 @@ exports.doesAuthorExists = function (authorID, callback)
//check if the database entry of this author exists //check if the database entry of this author exists
db.get("globalAuthor:" + authorID, function (err, author) db.get("globalAuthor:" + authorID, function (err, author)
{ {
callback(err, author != null); if(ERR(err, callback)) return;
callback(null, author != null);
}); });
} }
@ -42,8 +44,9 @@ exports.getAuthor4Token = function (token, callback)
{ {
mapAuthorWithDBKey("token2author", token, function(err, author) mapAuthorWithDBKey("token2author", token, function(err, author)
{ {
if(ERR(err, callback)) return;
//return only the sub value authorID //return only the sub value authorID
callback(err, author ? author.authorID : author); callback(null, author ? author.authorID : author);
}); });
} }
@ -56,12 +59,7 @@ exports.createAuthorIfNotExistsFor = function (authorMapper, name, callback)
{ {
mapAuthorWithDBKey("mapper2author", authorMapper, function(err, author) mapAuthorWithDBKey("mapper2author", authorMapper, function(err, author)
{ {
//error? if(ERR(err, callback)) return;
if(err)
{
callback(err);
return;
}
//set the name of this author //set the name of this author
if(name) if(name)
@ -84,24 +82,14 @@ function mapAuthorWithDBKey (mapperkey, mapper, callback)
//try to map to an author //try to map to an author
db.get(mapperkey + ":" + mapper, function (err, author) db.get(mapperkey + ":" + mapper, function (err, author)
{ {
//error? if(ERR(err, callback)) return;
if(err)
{
callback(err);
return;
}
//there is no author with this mapper, so create one //there is no author with this mapper, so create one
if(author == null) if(author == null)
{ {
exports.createAuthor(null, function(err, author) exports.createAuthor(null, function(err, author)
{ {
//error? if(ERR(err, callback)) return;
if(err)
{
callback(err);
return;
}
//create the token2author relation //create the token2author relation
db.set(mapperkey + ":" + mapper, author.authorID); db.set(mapperkey + ":" + mapper, author.authorID);

View file

@ -18,6 +18,7 @@
* limitations under the License. * limitations under the License.
*/ */
var ERR = require("async-stacktrace");
var db = require("./DB").db; var db = require("./DB").db;
var async = require("async"); var async = require("async");
var padManager = require("./PadManager"); var padManager = require("./PadManager");
@ -34,13 +35,10 @@ exports.deleteGroup = function(groupID, callback)
//try to get the group entry //try to get the group entry
db.get("group:" + groupID, function (err, _group) db.get("group:" + groupID, function (err, _group)
{ {
//error if(ERR(err, callback)) return;
if(err)
{
callback(err);
}
//group does not exist //group does not exist
else if(_group == null) if(_group == null)
{ {
callback({stop: "groupID does not exist"}); callback({stop: "groupID does not exist"});
} }
@ -67,7 +65,7 @@ exports.deleteGroup = function(groupID, callback)
{ {
padManager.getPad(padID, function(err, pad) padManager.getPad(padID, function(err, pad)
{ {
if(err) {callback(err); return} if(ERR(err, callback)) return;
pad.remove(callback); pad.remove(callback);
}); });
@ -79,7 +77,7 @@ exports.deleteGroup = function(groupID, callback)
//try to get the group entry //try to get the group entry
db.get("group2sessions:" + groupID, function (err, group2sessions) db.get("group2sessions:" + groupID, function (err, group2sessions)
{ {
if(err) {callback(err); return} if(ERR(err, callback)) return;
//skip if there is no group2sessions entry //skip if there is no group2sessions entry
if(group2sessions == null) {callback(); return} if(group2sessions == null) {callback(); return}
@ -107,7 +105,8 @@ exports.deleteGroup = function(groupID, callback)
} }
], function(err) ], function(err)
{ {
callback(err); if(ERR(err, callback)) return;
callback();
}); });
} }
@ -116,7 +115,8 @@ exports.doesGroupExist = function(groupID, callback)
//try to get the group entry //try to get the group entry
db.get("group:" + groupID, function (err, group) db.get("group:" + groupID, function (err, group)
{ {
callback(err, group != null); if(ERR(err, callback)) return;
callback(null, group != null);
}); });
} }
@ -142,23 +142,14 @@ exports.createGroupIfNotExistsFor = function(groupMapper, callback)
//try to get a group for this mapper //try to get a group for this mapper
db.get("mapper2group:"+groupMapper, function(err, groupID) db.get("mapper2group:"+groupMapper, function(err, groupID)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err);
return;
}
//there is no group for this mapper, let's create a group //there is no group for this mapper, let's create a group
if(groupID == null) if(groupID == null)
{ {
exports.createGroup(function(err, responseObj) exports.createGroup(function(err, responseObj)
{ {
//check for errors if(ERR(err, callback)) return;
if(err)
{
callback(err);
return;
}
//create the mapper entry for this group //create the mapper entry for this group
db.set("mapper2group:"+groupMapper, responseObj.groupID); db.set("mapper2group:"+groupMapper, responseObj.groupID);
@ -169,7 +160,8 @@ exports.createGroupIfNotExistsFor = function(groupMapper, callback)
//there is a group for this mapper, let's return it //there is a group for this mapper, let's return it
else else
{ {
callback(err, {groupID: groupID}); if(ERR(err, callback)) return;
callback(null, {groupID: groupID});
} }
}); });
} }
@ -185,13 +177,10 @@ exports.createGroupPad = function(groupID, padName, text, callback)
{ {
exports.doesGroupExist(groupID, function(err, exists) exports.doesGroupExist(groupID, function(err, exists)
{ {
//error if(ERR(err, callback)) return;
if(err)
{
callback(err);
}
//group does not exist //group does not exist
else if(exists == false) if(exists == false)
{ {
callback({stop: "groupID does not exist"}); callback({stop: "groupID does not exist"});
} }
@ -207,13 +196,10 @@ exports.createGroupPad = function(groupID, padName, text, callback)
{ {
padManager.doesPadExists(padID, function(err, exists) padManager.doesPadExists(padID, function(err, exists)
{ {
//error if(ERR(err, callback)) return;
if(err)
{
callback(err);
}
//pad exists already //pad exists already
else if(exists == true) if(exists == true)
{ {
callback({stop: "padName does already exist"}); callback({stop: "padName does already exist"});
} }
@ -229,7 +215,8 @@ exports.createGroupPad = function(groupID, padName, text, callback)
{ {
padManager.getPad(padID, text, function(err) padManager.getPad(padID, text, function(err)
{ {
callback(err); if(ERR(err, callback)) return;
callback();
}); });
}, },
//create an entry in the group for this pad //create an entry in the group for this pad
@ -240,7 +227,8 @@ exports.createGroupPad = function(groupID, padName, text, callback)
} }
], function(err) ], function(err)
{ {
callback(err, {padID: padID}); if(ERR(err, callback)) return;
callback(null, {padID: padID});
}); });
} }
@ -248,13 +236,10 @@ exports.listPads = function(groupID, callback)
{ {
exports.doesGroupExist(groupID, function(err, exists) exports.doesGroupExist(groupID, function(err, exists)
{ {
//error if(ERR(err, callback)) return;
if(err)
{
callback(err);
}
//group does not exist //group does not exist
else if(exists == false) if(exists == false)
{ {
callback({stop: "groupID does not exist"}); callback({stop: "groupID does not exist"});
} }
@ -263,7 +248,8 @@ exports.listPads = function(groupID, callback)
{ {
db.getSub("group:" + groupID, ["pads"], function(err, pads) db.getSub("group:" + groupID, ["pads"], function(err, pads)
{ {
callback(err, {padIDs: pads}); if(ERR(err, callback)) return;
callback(null, {padIDs: pads});
}); });
} }
}); });

View file

@ -4,6 +4,7 @@
require('joose'); require('joose');
var ERR = require("async-stacktrace");
var Changeset = require("../utils/Changeset"); var Changeset = require("../utils/Changeset");
var AttributePoolFactory = require("../utils/AttributePoolFactory"); var AttributePoolFactory = require("../utils/AttributePoolFactory");
var db = require("./DB").db; var db = require("./DB").db;
@ -164,8 +165,9 @@ Class('Pad', {
{ {
db.getSub("pad:"+_this.id+":revs:"+keyRev, ["meta", "atext"], function(err, _atext) db.getSub("pad:"+_this.id+":revs:"+keyRev, ["meta", "atext"], function(err, _atext)
{ {
if(ERR(err, callback)) return;
atext = Changeset.cloneAText(_atext); atext = Changeset.cloneAText(_atext);
callback(err); callback();
}); });
}, },
//get all needed changesets //get all needed changesets
@ -175,8 +177,9 @@ Class('Pad', {
{ {
_this.getRevisionChangeset(item, function(err, changeset) _this.getRevisionChangeset(item, function(err, changeset)
{ {
if(ERR(err, callback)) return;
changesets[item] = changeset; changesets[item] = changeset;
callback(err); callback();
}); });
}, callback); }, callback);
} }
@ -199,7 +202,8 @@ Class('Pad', {
} }
], function(err) ], function(err)
{ {
callback(err, atext); if(ERR(err, callback)) return;
callback(null, atext);
}); });
}, },
@ -247,8 +251,9 @@ Class('Pad', {
{ {
db.get("pad:"+_this.id+":chat:"+entryNum, function(err, _entry) db.get("pad:"+_this.id+":chat:"+entryNum, function(err, _entry)
{ {
if(ERR(err, callback)) return;
entry = _entry; entry = _entry;
callback(err); callback();
}); });
}, },
//add the authorName //add the authorName
@ -264,13 +269,15 @@ Class('Pad', {
//get the authorName //get the authorName
authorManager.getAuthorName(entry.userId, function(err, authorName) authorManager.getAuthorName(entry.userId, function(err, authorName)
{ {
if(ERR(err, callback)) return;
entry.userName = authorName; entry.userName = authorName;
callback(err); callback();
}); });
} }
], function(err) ], function(err)
{ {
callback(err, entry); if(ERR(err, callback)) return;
callback(null, entry);
}); });
}, },
@ -311,11 +318,14 @@ Class('Pad', {
{ {
_this.getChatMessage(entryObject.entryNum, function(err, entry) _this.getChatMessage(entryObject.entryNum, function(err, entry)
{ {
if(ERR(err, callback)) return;
entries[entryObject.order] = entry; entries[entryObject.order] = entry;
callback(err); callback();
}); });
}, function(err) }, function(err)
{ {
if(ERR(err, callback)) return;
//sort out broken chat entries //sort out broken chat entries
//it looks like in happend in the past that the chat head was //it looks like in happend in the past that the chat head was
//incremented, but the chat message wasn't added //incremented, but the chat message wasn't added
@ -328,7 +338,7 @@ Class('Pad', {
console.warn("WARNING: Found broken chat entry in pad " + _this.id); console.warn("WARNING: Found broken chat entry in pad " + _this.id);
} }
callback(err, cleanedEntries); callback(null, cleanedEntries);
}); });
}, },
@ -345,11 +355,7 @@ Class('Pad', {
//try to load the pad //try to load the pad
db.get("pad:"+this.id, function(err, value) db.get("pad:"+this.id, function(err, value)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err, null);
return;
}
//if this pad exists, load it //if this pad exists, load it
if(value != null) if(value != null)
@ -410,7 +416,7 @@ Class('Pad', {
db.get("group:" + groupID, function (err, group) db.get("group:" + groupID, function (err, group)
{ {
if(err) {callback(err); return} if(ERR(err, callback)) return;
//remove the pad entry //remove the pad entry
delete group.pads[padID]; delete group.pads[padID];
@ -432,7 +438,7 @@ Class('Pad', {
{ {
readOnlyManager.getReadOnlyId(padID, function(err, readonlyID) readOnlyManager.getReadOnlyId(padID, function(err, readonlyID)
{ {
if(err) {callback(err); return} if(ERR(err, callback)) return;
db.remove("pad2readonly:" + padID); db.remove("pad2readonly:" + padID);
db.remove("readonly2pad:" + readonlyID); db.remove("readonly2pad:" + readonlyID);
@ -475,7 +481,8 @@ Class('Pad', {
} }
], function(err) ], function(err)
{ {
callback(err); if(ERR(err, callback)) return;
callback();
}) })
}, },
//set in db //set in db

View file

@ -18,6 +18,7 @@
* limitations under the License. * limitations under the License.
*/ */
var ERR = require("async-stacktrace");
require("../db/Pad"); require("../db/Pad");
var db = require("./DB").db; var db = require("./DB").db;
@ -90,15 +91,10 @@ exports.getPad = function(id, text, callback)
//initalize the pad //initalize the pad
pad.init(text, function(err) pad.init(text, function(err)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err, null); globalPads.set(id, pad);
} callback(null, pad);
else
{
globalPads.set(id, pad);
callback(null, pad);
}
}); });
} }
} }
@ -108,7 +104,8 @@ exports.doesPadExists = function(padId, callback)
{ {
db.get("pad:"+padId, function(err, value) db.get("pad:"+padId, function(err, value)
{ {
callback(err, value != null); if(ERR(err, callback)) return;
callback(null, value != null);
}); });
} }

View file

@ -18,6 +18,7 @@
* limitations under the License. * limitations under the License.
*/ */
var ERR = require("async-stacktrace");
var db = require("./DB").db; var db = require("./DB").db;
var async = require("async"); var async = require("async");
@ -55,8 +56,9 @@ exports.getReadOnlyId = function (padId, callback)
} }
], function(err) ], function(err)
{ {
if(ERR(err, callback)) return;
//return the results //return the results
callback(err, readOnlyId); callback(null, readOnlyId);
}) })
} }

View file

@ -17,7 +17,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
var ERR = require("async-stacktrace");
var db = require("./DB").db; var db = require("./DB").db;
var async = require("async"); var async = require("async");
var authorManager = require("./AuthorManager"); var authorManager = require("./AuthorManager");
@ -56,6 +57,8 @@ exports.checkAccess = function (padID, sessionID, token, password, callback)
//get author for this token //get author for this token
authorManager.getAuthor4Token(token, function(err, author) authorManager.getAuthor4Token(token, function(err, author)
{ {
if(ERR(err, callback)) return;
// assume user has access // assume user has access
statusObject = {accessStatus: "grant", authorID: author}; statusObject = {accessStatus: "grant", authorID: author};
// user can't create pads // user can't create pads
@ -64,17 +67,19 @@ exports.checkAccess = function (padID, sessionID, token, password, callback)
// check if pad exists // check if pad exists
padManager.doesPadExists(padID, function(err, exists) padManager.doesPadExists(padID, function(err, exists)
{ {
if(ERR(err, callback)) return;
// pad doesn't exist - user can't have access // pad doesn't exist - user can't have access
if(!exists) statusObject.accessStatus = "deny"; if(!exists) statusObject.accessStatus = "deny";
// grant or deny access, with author of token // grant or deny access, with author of token
callback(err, statusObject); callback(null, statusObject);
}); });
} }
// user may create new pads - no need to check anything // user may create new pads - no need to check anything
else else
{ {
// grant access, with author of token // grant access, with author of token
callback(err, statusObject); callback(null, statusObject);
} }
}) })
@ -102,8 +107,9 @@ exports.checkAccess = function (padID, sessionID, token, password, callback)
{ {
padManager.doesPadExists(padID, function(err, exists) padManager.doesPadExists(padID, function(err, exists)
{ {
if(ERR(err, callback)) return;
padExists = exists; padExists = exists;
callback(err); callback();
}); });
}, },
//get informations about this session //get informations about this session
@ -118,7 +124,7 @@ exports.checkAccess = function (padID, sessionID, token, password, callback)
return; return;
} }
if(err) {callback(err); return} if(ERR(err, callback)) return;
var now = Math.floor(new Date().getTime()/1000); var now = Math.floor(new Date().getTime()/1000);
@ -139,8 +145,9 @@ exports.checkAccess = function (padID, sessionID, token, password, callback)
//get author for this token //get author for this token
authorManager.getAuthor4Token(token, function(err, author) authorManager.getAuthor4Token(token, function(err, author)
{ {
if(ERR(err, callback)) return;
tokenAuthor = author; tokenAuthor = author;
callback(err); callback();
}); });
} }
], callback); ], callback);
@ -157,7 +164,7 @@ exports.checkAccess = function (padID, sessionID, token, password, callback)
padManager.getPad(padID, function(err, pad) padManager.getPad(padID, function(err, pad)
{ {
if(err) {callback(err); return} if(ERR(err, callback)) return;
//is it a public pad? //is it a public pad?
isPublic = pad.getPublicStatus(); isPublic = pad.getPublicStatus();
@ -265,6 +272,7 @@ exports.checkAccess = function (padID, sessionID, token, password, callback)
} }
], function(err) ], function(err)
{ {
callback(err, statusObject); if(ERR(err, callback)) return;
callback(null, statusObject);
}); });
} }

View file

@ -18,6 +18,7 @@
* limitations under the License. * limitations under the License.
*/ */
var ERR = require("async-stacktrace");
var db = require("./DB").db; var db = require("./DB").db;
var async = require("async"); var async = require("async");
var groupMangager = require("./GroupManager"); var groupMangager = require("./GroupManager");
@ -28,7 +29,8 @@ exports.doesSessionExist = function(sessionID, callback)
//check if the database entry of this session exists //check if the database entry of this session exists
db.get("session:" + sessionID, function (err, session) db.get("session:" + sessionID, function (err, session)
{ {
callback(err, session != null); if(ERR(err, callback)) return;
callback(null, session != null);
}); });
} }
@ -45,13 +47,10 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
{ {
groupMangager.doesGroupExist(groupID, function(err, exists) groupMangager.doesGroupExist(groupID, function(err, exists)
{ {
//error if(ERR(err, callback)) return;
if(err)
{
callback(err);
}
//group does not exist //group does not exist
else if(exists == false) if(exists == false)
{ {
callback({stop: "groupID does not exist"}); callback({stop: "groupID does not exist"});
} }
@ -67,13 +66,10 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
{ {
authorMangager.doesAuthorExists(authorID, function(err, exists) authorMangager.doesAuthorExists(authorID, function(err, exists)
{ {
//error if(ERR(err, callback)) return;
if(err)
{
callback(err);
}
//author does not exist //author does not exist
else if(exists == false) if(exists == false)
{ {
callback({stop: "authorID does not exist"}); callback({stop: "authorID does not exist"});
} }
@ -137,12 +133,7 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
//get the entry //get the entry
db.get("group2sessions:" + groupID, function(err, group2sessions) db.get("group2sessions:" + groupID, function(err, group2sessions)
{ {
//did a error happen? if(ERR(err, callback)) return;
if(err)
{
callback(err);
return;
}
//the entry doesn't exist so far, let's create it //the entry doesn't exist so far, let's create it
if(group2sessions == null) if(group2sessions == null)
@ -165,12 +156,7 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
//get the entry //get the entry
db.get("author2sessions:" + authorID, function(err, author2sessions) db.get("author2sessions:" + authorID, function(err, author2sessions)
{ {
//did a error happen? if(ERR(err, callback)) return;
if(err)
{
callback(err);
return;
}
//the entry doesn't exist so far, let's create it //the entry doesn't exist so far, let's create it
if(author2sessions == null) if(author2sessions == null)
@ -189,8 +175,10 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
} }
], function(err) ], function(err)
{ {
if(ERR(err, callback)) return;
//return error and sessionID //return error and sessionID
callback(err, {sessionID: sessionID}); callback(null, {sessionID: sessionID});
}) })
} }
@ -199,13 +187,10 @@ exports.getSessionInfo = function(sessionID, callback)
//check if the database entry of this session exists //check if the database entry of this session exists
db.get("session:" + sessionID, function (err, session) db.get("session:" + sessionID, function (err, session)
{ {
//error if(ERR(err, callback)) return;
if(err)
{
callback(err);
}
//session does not exists //session does not exists
else if(session == null) if(session == null)
{ {
callback({stop: "sessionID does not exist"}) callback({stop: "sessionID does not exist"})
} }
@ -231,13 +216,10 @@ exports.deleteSession = function(sessionID, callback)
//get the session entry //get the session entry
db.get("session:" + sessionID, function (err, session) db.get("session:" + sessionID, function (err, session)
{ {
//error if(ERR(err, callback)) return;
if(err)
{
callback(err);
}
//session does not exists //session does not exists
else if(session == null) if(session == null)
{ {
callback({stop: "sessionID does not exist"}) callback({stop: "sessionID does not exist"})
} }
@ -256,8 +238,9 @@ exports.deleteSession = function(sessionID, callback)
{ {
db.get("group2sessions:" + groupID, function (err, _group2sessions) db.get("group2sessions:" + groupID, function (err, _group2sessions)
{ {
if(ERR(err, callback)) return;
group2sessions = _group2sessions; group2sessions = _group2sessions;
callback(err); callback();
}); });
}, },
//get the author2sessions entry //get the author2sessions entry
@ -265,8 +248,9 @@ exports.deleteSession = function(sessionID, callback)
{ {
db.get("author2sessions:" + authorID, function (err, _author2sessions) db.get("author2sessions:" + authorID, function (err, _author2sessions)
{ {
if(ERR(err, callback)) return;
author2sessions = _author2sessions; author2sessions = _author2sessions;
callback(err); callback();
}); });
}, },
//remove the values from the database //remove the values from the database
@ -287,7 +271,8 @@ exports.deleteSession = function(sessionID, callback)
} }
], function(err) ], function(err)
{ {
callback(err); if(ERR(err, callback)) return;
callback();
}) })
} }
@ -295,13 +280,10 @@ exports.listSessionsOfGroup = function(groupID, callback)
{ {
groupMangager.doesGroupExist(groupID, function(err, exists) groupMangager.doesGroupExist(groupID, function(err, exists)
{ {
//error if(ERR(err, callback)) return;
if(err)
{
callback(err);
}
//group does not exist //group does not exist
else if(exists == false) if(exists == false)
{ {
callback({stop: "groupID does not exist"}); callback({stop: "groupID does not exist"});
} }
@ -317,13 +299,10 @@ exports.listSessionsOfAuthor = function(authorID, callback)
{ {
authorMangager.doesAuthorExists(authorID, function(err, exists) authorMangager.doesAuthorExists(authorID, function(err, exists)
{ {
//error if(ERR(err, callback)) return;
if(err)
{
callback(err);
}
//group does not exist //group does not exist
else if(exists == false) if(exists == false)
{ {
callback({stop: "authorID does not exist"}); callback({stop: "authorID does not exist"});
} }
@ -346,8 +325,9 @@ function listSessionsWithDBKey (dbkey, callback)
//get the group2sessions entry //get the group2sessions entry
db.get(dbkey, function(err, sessionObject) db.get(dbkey, function(err, sessionObject)
{ {
if(ERR(err, callback)) return;
sessions = sessionObject ? sessionObject.sessionIDs : null; sessions = sessionObject ? sessionObject.sessionIDs : null;
callback(err); callback();
}); });
}, },
function(callback) function(callback)
@ -364,14 +344,16 @@ function listSessionsWithDBKey (dbkey, callback)
{ {
exports.getSessionInfo(sessionID, function(err, sessionInfo) exports.getSessionInfo(sessionID, function(err, sessionInfo)
{ {
if(ERR(err, callback)) return;
sessions[sessionID] = sessionInfo; sessions[sessionID] = sessionInfo;
callback(err); callback();
}); });
}, callback); }, callback);
} }
], function(err) ], function(err)
{ {
callback(err, sessions); if(ERR(err, callback)) return;
callback(null, sessions);
}); });
} }

View file

@ -18,6 +18,7 @@
* limitations under the License. * limitations under the License.
*/ */
var ERR = require("async-stacktrace");
var fs = require("fs"); var fs = require("fs");
var api = require("../db/API"); var api = require("../db/API");
@ -122,7 +123,7 @@ exports.handle = function(functionName, fields, req, res)
else else
{ {
res.send({code: 2, message: "internal error", data: null}); res.send({code: 2, message: "internal error", data: null});
throw (err); ERR(err);
} }
}); });

View file

@ -18,6 +18,7 @@
* limitations under the License. * limitations under the License.
*/ */
var ERR = require("async-stacktrace");
var exporthtml = require("../utils/ExportHtml"); var exporthtml = require("../utils/ExportHtml");
var padManager = require("../db/PadManager"); var padManager = require("../db/PadManager");
var async = require("async"); var async = require("async");
@ -50,8 +51,7 @@ exports.doExport = function(req, res, padId, type)
{ {
padManager.getPad(padId, function(err, pad) padManager.getPad(padId, function(err, pad)
{ {
if(err) ERR(err);
throw err;
res.send(pad.text()); res.send(pad.text());
}); });
@ -68,8 +68,9 @@ exports.doExport = function(req, res, padId, type)
{ {
exporthtml.getPadHTMLDocument(padId, null, false, function(err, _html) exporthtml.getPadHTMLDocument(padId, null, false, function(err, _html)
{ {
if(ERR(err, callback)) return;
html = _html; html = _html;
callback(err); callback();
}); });
}, },
//decide what to do with the html export //decide what to do with the html export
@ -113,19 +114,23 @@ exports.doExport = function(req, res, padId, type)
function(callback) function(callback)
{ {
//100ms delay to accomidate for slow windows fs //100ms delay to accomidate for slow windows fs
if(os.type().indexOf("Windows") > -1) if(os.type().indexOf("Windows") > -1)
{ {
setTimeout(function() setTimeout(function()
{ {
fs.unlink(destFile, callback); fs.unlink(destFile, callback);
}, 100); }, 100);
} }
else
{
fs.unlink(destFile, callback);
}
} }
], callback); ], callback);
} }
], function(err) ], function(err)
{ {
if(err && err != "stop") throw err; if(err && err != "stop") ERR(err);
}) })
} }
}; };

View file

@ -18,6 +18,7 @@
* limitations under the License. * limitations under the License.
*/ */
var ERR = require("async-stacktrace");
var padManager = require("../db/PadManager"); var padManager = require("../db/PadManager");
var padMessageHandler = require("./PadMessageHandler"); var padMessageHandler = require("./PadMessageHandler");
var async = require("async"); var async = require("async");
@ -122,8 +123,9 @@ exports.doImport = function(req, res, padId)
{ {
padManager.getPad(padId, function(err, _pad) padManager.getPad(padId, function(err, _pad)
{ {
if(ERR(err, callback)) return;
pad = _pad; pad = _pad;
callback(err); callback();
}); });
}, },
@ -132,17 +134,22 @@ exports.doImport = function(req, res, padId)
{ {
fs.readFile(destFile, "utf8", function(err, _text) fs.readFile(destFile, "utf8", function(err, _text)
{ {
if(ERR(err, callback)) return;
text = _text; text = _text;
//node on windows has a delay on releasing of the file lock. //node on windows has a delay on releasing of the file lock.
//We add a 100ms delay to work around this //We add a 100ms delay to work around this
if(os.type().indexOf("Windows") > -1) if(os.type().indexOf("Windows") > -1)
{ {
setTimeout(function() setTimeout(function()
{ {
callback(err); callback();
}, 100); }, 100);
} }
else
{
callback();
}
}); });
}, },
@ -176,7 +183,7 @@ exports.doImport = function(req, res, padId)
return; return;
} }
if(err) throw err; ERR(err);
//close the connection //close the connection
res.send("ok"); res.send("ok");

View file

@ -18,6 +18,7 @@
* limitations under the License. * limitations under the License.
*/ */
var ERR = require("async-stacktrace");
var async = require("async"); var async = require("async");
var padManager = require("../db/PadManager"); var padManager = require("../db/PadManager");
var Changeset = require("../utils/Changeset"); var Changeset = require("../utils/Changeset");
@ -107,7 +108,7 @@ exports.handleDisconnect = function(client)
//get the author color out of the db //get the author color out of the db
authorManager.getAuthorColorId(author, function(err, color) authorManager.getAuthorColorId(author, function(err, color)
{ {
if(err) throw err; ERR(err);
//prepare the notification for the other users on the pad, that this user left //prepare the notification for the other users on the pad, that this user left
var messageToTheOtherUsers = { var messageToTheOtherUsers = {
@ -218,16 +219,18 @@ function handleChatMessage(client, message)
{ {
padManager.getPad(padId, function(err, _pad) padManager.getPad(padId, function(err, _pad)
{ {
if(ERR(err, callback)) return;
pad = _pad; pad = _pad;
callback(err); callback();
}); });
}, },
function(callback) function(callback)
{ {
authorManager.getAuthorName(userId, function(err, _userName) authorManager.getAuthorName(userId, function(err, _userName)
{ {
if(ERR(err, callback)) return;
userName = _userName; userName = _userName;
callback(err); callback();
}); });
}, },
//save the chat message and broadcast it //save the chat message and broadcast it
@ -257,7 +260,7 @@ function handleChatMessage(client, message)
} }
], function(err) ], function(err)
{ {
if(err) throw err; ERR(err);
}); });
} }
@ -375,8 +378,9 @@ function handleUserChanges(client, message)
{ {
padManager.getPad(session2pad[client.id], function(err, value) padManager.getPad(session2pad[client.id], function(err, value)
{ {
if(ERR(err, callback)) return;
pad = value; pad = value;
callback(err); callback();
}); });
}, },
//create the changeset //create the changeset
@ -422,16 +426,10 @@ function handleUserChanges(client, message)
pad.getRevisionChangeset(r, function(err, c) pad.getRevisionChangeset(r, function(err, c)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err); changeset = Changeset.follow(c, changeset, false, apool);
return; callback(null);
}
else
{
changeset = Changeset.follow(c, changeset, false, apool);
callback(null);
}
}); });
}, },
//use the callback of the series function //use the callback of the series function
@ -469,7 +467,7 @@ function handleUserChanges(client, message)
} }
], function(err) ], function(err)
{ {
if(err) throw err; ERR(err);
}); });
} }
@ -502,25 +500,23 @@ exports.updatePadClients = function(pad, callback)
{ {
pad.getRevisionAuthor(r, function(err, value) pad.getRevisionAuthor(r, function(err, value)
{ {
if(ERR(err, callback)) return;
author = value; author = value;
callback(err); callback();
}); });
}, },
function (callback) function (callback)
{ {
pad.getRevisionChangeset(r, function(err, value) pad.getRevisionChangeset(r, function(err, value)
{ {
if(ERR(err, callback)) return;
revChangeset = value; revChangeset = value;
callback(err); callback();
}); });
} }
], function(err) ], function(err)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err);
return;
}
if(author == sessioninfos[session].author) if(author == sessioninfos[session].author)
{ {
@ -633,7 +629,7 @@ function handleClientReady(client, message)
{ {
securityManager.checkAccess (message.padId, message.sessionID, message.token, message.password, function(err, statusObject) securityManager.checkAccess (message.padId, message.sessionID, message.token, message.password, function(err, statusObject)
{ {
if(err) {callback(err); return} if(ERR(err, callback)) return;
//access was granted //access was granted
if(statusObject.accessStatus == "grant") if(statusObject.accessStatus == "grant")
@ -657,8 +653,9 @@ function handleClientReady(client, message)
{ {
authorManager.getAuthorColorId(author, function(err, value) authorManager.getAuthorColorId(author, function(err, value)
{ {
if(ERR(err, callback)) return;
authorColorId = value; authorColorId = value;
callback(err); callback();
}); });
}, },
//get author name //get author name
@ -666,24 +663,27 @@ function handleClientReady(client, message)
{ {
authorManager.getAuthorName(author, function(err, value) authorManager.getAuthorName(author, function(err, value)
{ {
if(ERR(err, callback)) return;
authorName = value; authorName = value;
callback(err); callback();
}); });
}, },
function(callback) function(callback)
{ {
padManager.getPad(message.padId, function(err, value) padManager.getPad(message.padId, function(err, value)
{ {
if(ERR(err, callback)) return;
pad = value; pad = value;
callback(err); callback();
}); });
}, },
function(callback) function(callback)
{ {
readOnlyManager.getReadOnlyId(message.padId, function(err, value) readOnlyManager.getReadOnlyId(message.padId, function(err, value)
{ {
if(ERR(err, callback)) return;
readOnlyId = value; readOnlyId = value;
callback(err); callback();
}); });
} }
], callback); ], callback);
@ -701,9 +701,10 @@ function handleClientReady(client, message)
{ {
authorManager.getAuthor(authorId, function(err, author) authorManager.getAuthor(authorId, function(err, author)
{ {
if(ERR(err, callback)) return;
delete author.timestamp; delete author.timestamp;
historicalAuthorData[authorId] = author; historicalAuthorData[authorId] = author;
callback(err); callback();
}); });
}, callback); }, callback);
}, },
@ -712,8 +713,9 @@ function handleClientReady(client, message)
{ {
pad.getLastChatMessages(100, function(err, _chatMessages) pad.getLastChatMessages(100, function(err, _chatMessages)
{ {
if(ERR(err, callback)) return;
chatMessages = _chatMessages; chatMessages = _chatMessages;
callback(err); callback();
}); });
} }
], callback); ], callback);
@ -859,16 +861,18 @@ function handleClientReady(client, message)
{ {
authorManager.getAuthorColorId(sessioninfos[sessionID].author, function(err, value) authorManager.getAuthorColorId(sessioninfos[sessionID].author, function(err, value)
{ {
if(ERR(err, callback)) return;
sessionAuthorColorId = value; sessionAuthorColorId = value;
callback(err); callback();
}) })
}, },
function(callback) function(callback)
{ {
authorManager.getAuthorName(sessioninfos[sessionID].author, function(err, value) authorManager.getAuthorName(sessioninfos[sessionID].author, function(err, value)
{ {
if(ERR(err, callback)) return;
sessionAuthorName = value; sessionAuthorName = value;
callback(err); callback();
}) })
} }
],callback); ],callback);
@ -903,6 +907,6 @@ function handleClientReady(client, message)
} }
],function(err) ],function(err)
{ {
if(err) throw err; ERR(err);
}); });
} }

View file

@ -19,6 +19,7 @@
* limitations under the License. * limitations under the License.
*/ */
var ERR = require("async-stacktrace");
var log4js = require('log4js'); var log4js = require('log4js');
var messageLogger = log4js.getLogger("message"); var messageLogger = log4js.getLogger("message");
var securityManager = require("../db/SecurityManager"); var securityManager = require("../db/SecurityManager");
@ -109,7 +110,7 @@ exports.setSocketIO = function(_socket)
{ {
securityManager.checkAccess (message.padId, message.sessionID, message.token, message.password, function(err, statusObject) securityManager.checkAccess (message.padId, message.sessionID, message.token, message.password, function(err, statusObject)
{ {
if(err) throw err; ERR(err);
//access was granted, mark the client as authorized and handle the message //access was granted, mark the client as authorized and handle the message
if(statusObject.accessStatus == "grant") if(statusObject.accessStatus == "grant")

View file

@ -18,6 +18,7 @@
* limitations under the License. * limitations under the License.
*/ */
var ERR = require("async-stacktrace");
var async = require("async"); var async = require("async");
var padManager = require("../db/PadManager"); var padManager = require("../db/PadManager");
var Changeset = require("../utils/Changeset"); var Changeset = require("../utils/Changeset");
@ -92,7 +93,7 @@ function handleClientReady(client, message)
//send the timeslider client the clientVars, with this values its able to start //send the timeslider client the clientVars, with this values its able to start
createTimesliderClientVars (message.padId, function(err, clientVars) createTimesliderClientVars (message.padId, function(err, clientVars)
{ {
if(err) throw err; ERR(err);
client.json.send({type: "CLIENT_VARS", data: clientVars}); client.json.send({type: "CLIENT_VARS", data: clientVars});
}) })
@ -138,7 +139,7 @@ function handleChangesetRequest(client, message)
//build the requested rough changesets and send them back //build the requested rough changesets and send them back
getChangesetInfo(padId, start, end, granularity, function(err, changesetInfo) getChangesetInfo(padId, start, end, granularity, function(err, changesetInfo)
{ {
if(err) throw err; ERR(err);
var data = changesetInfo; var data = changesetInfo;
data.requestID = message.data.requestID; data.requestID = message.data.requestID;
@ -171,8 +172,9 @@ function createTimesliderClientVars (padId, callback)
{ {
padManager.getPad(padId, function(err, _pad) padManager.getPad(padId, function(err, _pad)
{ {
if(ERR(err, callback)) return;
pad = _pad; pad = _pad;
callback(err); callback();
}); });
}, },
//get all authors and add them to //get all authors and add them to
@ -187,15 +189,17 @@ function createTimesliderClientVars (padId, callback)
{ {
authorManager.getAuthor(authorId, function(err, author) authorManager.getAuthor(authorId, function(err, author)
{ {
if(ERR(err, callback)) return;
historicalAuthorData[authorId] = author; historicalAuthorData[authorId] = author;
callback(err); callback();
}); });
}, function(err) }, function(err)
{ {
if(ERR(err, callback)) return;
//add historicalAuthorData to the clientVars and continue //add historicalAuthorData to the clientVars and continue
clientVars.historicalAuthorData = historicalAuthorData; clientVars.historicalAuthorData = historicalAuthorData;
clientVars.initialStyledContents.historicalAuthorData = historicalAuthorData; clientVars.initialStyledContents.historicalAuthorData = historicalAuthorData;
callback(err); callback();
}); });
}, },
//get the timestamp of the last revision //get the timestamp of the last revision
@ -203,8 +207,9 @@ function createTimesliderClientVars (padId, callback)
{ {
pad.getRevisionDate(pad.getHeadRevisionNumber(), function(err, date) pad.getRevisionDate(pad.getHeadRevisionNumber(), function(err, date)
{ {
if(ERR(err, callback)) return;
clientVars.currentTime = date; clientVars.currentTime = date;
callback(err); callback();
}); });
}, },
function(callback) function(callback)
@ -235,14 +240,16 @@ function createTimesliderClientVars (padId, callback)
Math.floor(lastRev / topGranularity)*topGranularity+topGranularity, granularity, Math.floor(lastRev / topGranularity)*topGranularity+topGranularity, granularity,
function(err, changeset) function(err, changeset)
{ {
if(ERR(err, callback)) return;
clientVars.initialChangesets.push(changeset); clientVars.initialChangesets.push(changeset);
callback(err); callback();
}); });
}, callback); }, callback);
} }
], function(err) ], function(err)
{ {
callback(err, clientVars); if(ERR(err, callback)) return;
callback(null, clientVars);
}); });
} }
@ -267,8 +274,9 @@ function getChangesetInfo(padId, startNum, endNum, granularity, callback)
{ {
padManager.getPad(padId, function(err, _pad) padManager.getPad(padId, function(err, _pad)
{ {
if(ERR(err, callback)) return;
pad = _pad; pad = _pad;
callback(err); callback();
}); });
}, },
function(callback) function(callback)
@ -309,8 +317,9 @@ function getChangesetInfo(padId, startNum, endNum, granularity, callback)
{ {
composePadChangesets(padId, item.start, item.end, function(err, changeset) composePadChangesets(padId, item.start, item.end, function(err, changeset)
{ {
if(ERR(err, callback)) return;
composedChangesets[item.start + "/" + item.end] = changeset; composedChangesets[item.start + "/" + item.end] = changeset;
callback(err); callback();
}); });
}, callback); }, callback);
}, },
@ -321,8 +330,9 @@ function getChangesetInfo(padId, startNum, endNum, granularity, callback)
{ {
pad.getRevisionDate(revNum, function(err, revDate) pad.getRevisionDate(revNum, function(err, revDate)
{ {
if(ERR(err, callback)) return;
revisionDate[revNum] = Math.floor(revDate/1000); revisionDate[revNum] = Math.floor(revDate/1000);
callback(err); callback();
}); });
}, callback); }, callback);
}, },
@ -331,8 +341,9 @@ function getChangesetInfo(padId, startNum, endNum, granularity, callback)
{ {
getPadLines(padId, startNum-1, function(err, _lines) getPadLines(padId, startNum-1, function(err, _lines)
{ {
if(ERR(err, callback)) return;
lines = _lines; lines = _lines;
callback(err); callback();
}); });
} }
], callback); ], callback);
@ -383,20 +394,15 @@ function getChangesetInfo(padId, startNum, endNum, granularity, callback)
} }
], function(err) ], function(err)
{ {
if(err) if(ERR(err, callback)) return;
{
callback(err); callback(null, {forwardsChangesets: forwardsChangesets,
} backwardsChangesets: backwardsChangesets,
else apool: apool.toJsonable(),
{ actualEndNum: endNum,
callback(null, {forwardsChangesets: forwardsChangesets, timeDeltas: timeDeltas,
backwardsChangesets: backwardsChangesets, start: startNum,
apool: apool.toJsonable(), granularity: granularity });
actualEndNum: endNum,
timeDeltas: timeDeltas,
start: startNum,
granularity: granularity });
}
}); });
} }
@ -416,8 +422,9 @@ function getPadLines(padId, revNum, callback)
{ {
padManager.getPad(padId, function(err, _pad) padManager.getPad(padId, function(err, _pad)
{ {
if(ERR(err, callback)) return;
pad = _pad; pad = _pad;
callback(err); callback();
}); });
}, },
//get the atext //get the atext
@ -427,8 +434,9 @@ function getPadLines(padId, revNum, callback)
{ {
pad.getInternalRevisionAText(revNum, function(err, _atext) pad.getInternalRevisionAText(revNum, function(err, _atext)
{ {
if(ERR(err, callback)) return;
atext = _atext; atext = _atext;
callback(err); callback();
}); });
} }
else else
@ -445,7 +453,8 @@ function getPadLines(padId, revNum, callback)
} }
], function(err) ], function(err)
{ {
callback(err, result); if(ERR(err, callback)) return;
callback(null, result);
}); });
} }
@ -465,8 +474,9 @@ function composePadChangesets(padId, startNum, endNum, callback)
{ {
padManager.getPad(padId, function(err, _pad) padManager.getPad(padId, function(err, _pad)
{ {
if(ERR(err, callback)) return;
pad = _pad; pad = _pad;
callback(err); callback();
}); });
}, },
//fetch all changesets we need //fetch all changesets we need
@ -486,8 +496,9 @@ function composePadChangesets(padId, startNum, endNum, callback)
{ {
pad.getRevisionChangeset(revNum, function(err, value) pad.getRevisionChangeset(revNum, function(err, value)
{ {
if(ERR(err, callback)) return;
changesets[revNum] = value; changesets[revNum] = value;
callback(err); callback();
}); });
},callback); },callback);
}, },
@ -509,7 +520,7 @@ function composePadChangesets(padId, startNum, endNum, callback)
//return err and changeset //return err and changeset
function(err) function(err)
{ {
if(err) throw err; if(ERR(err, callback)) return;
callback(err, changeset); callback(null, changeset);
}); });
} }

View file

@ -20,6 +20,7 @@
* limitations under the License. * limitations under the License.
*/ */
var ERR = require("async-stacktrace");
var log4js = require('log4js'); var log4js = require('log4js');
var os = require("os"); var os = require("os");
var socketio = require('socket.io'); var socketio = require('socket.io');
@ -116,7 +117,6 @@ async.waterfall([
//serve minified files //serve minified files
app.get('/minified/:id', function(req, res, next) app.get('/minified/:id', function(req, res, next)
{ {
throw new Error();
res.header("Server", serverName); res.header("Server", serverName);
var id = req.params.id; var id = req.params.id;
@ -136,7 +136,7 @@ async.waterfall([
{ {
securityManager.checkAccess(req.params.pad, req.cookies.sessionid, req.cookies.token, req.cookies.password, function(err, accessObj) securityManager.checkAccess(req.params.pad, req.cookies.sessionid, req.cookies.token, req.cookies.password, function(err, accessObj)
{ {
if(err) throw err; if(ERR(err, callback)) return;
//there is access, continue //there is access, continue
if(accessObj.accessStatus == "grant") if(accessObj.accessStatus == "grant")
@ -166,12 +166,14 @@ async.waterfall([
{ {
readOnlyManager.getPadId(req.params.id, function(err, _padId) readOnlyManager.getPadId(req.params.id, function(err, _padId)
{ {
if(ERR(err, callback)) return;
padId = _padId; padId = _padId;
//we need that to tell hasPadAcess about the pad //we need that to tell hasPadAcess about the pad
req.params.pad = padId; req.params.pad = padId;
callback(err); callback();
}); });
}, },
//render the html document //render the html document
@ -189,8 +191,9 @@ async.waterfall([
//render the html document //render the html document
exporthtml.getPadHTMLDocument(padId, null, false, function(err, _html) exporthtml.getPadHTMLDocument(padId, null, false, function(err, _html)
{ {
if(ERR(err, callback)) return;
html = _html; html = _html;
callback(err); callback();
}); });
}); });
} }
@ -198,7 +201,7 @@ async.waterfall([
{ {
//throw any unexpected error //throw any unexpected error
if(err && err != "notfound") if(err && err != "notfound")
throw err; ERR(err);
if(err == "notfound") if(err == "notfound")
res.send('404 - Not Found', 404); res.send('404 - Not Found', 404);

View file

@ -17,6 +17,7 @@
var async = require("async"); var async = require("async");
var Changeset = require("./Changeset"); var Changeset = require("./Changeset");
var padManager = require("../db/PadManager"); var padManager = require("../db/PadManager");
var ERR = require("async-stacktrace");
function getPadPlainText(pad, revNum) function getPadPlainText(pad, revNum)
{ {
@ -58,8 +59,9 @@ function getPadHTML(pad, revNum, callback)
{ {
pad.getInternalRevisionAText(revNum, function (err, revisionAtext) pad.getInternalRevisionAText(revNum, function (err, revisionAtext)
{ {
if(ERR(err, callback)) return;
atext = revisionAtext; atext = revisionAtext;
callback(err); callback();
}); });
} }
else else
@ -81,7 +83,8 @@ function getPadHTML(pad, revNum, callback)
function (err) function (err)
{ {
callback(err, html); if(ERR(err, callback)) return;
callback(null, html);
}); });
} }
@ -410,11 +413,7 @@ exports.getPadHTMLDocument = function (padId, revNum, noDocType, callback)
{ {
padManager.getPad(padId, function (err, pad) padManager.getPad(padId, function (err, pad)
{ {
if (err) if(ERR(err, callback)) return;
{
callback(err);
return;
}
var head = (noDocType ? '' : '<!doctype html>\n') + '<html lang="en">\n' + (noDocType ? '' : '<head>\n' + '<meta charset="utf-8">\n' + '<style> * { font-family: arial, sans-serif;\n' + 'font-size: 13px;\n' + 'line-height: 17px; }</style>\n' + '</head>\n') + '<body>'; var head = (noDocType ? '' : '<!doctype html>\n') + '<html lang="en">\n' + (noDocType ? '' : '<head>\n' + '<meta charset="utf-8">\n' + '<style> * { font-family: arial, sans-serif;\n' + 'font-size: 13px;\n' + 'line-height: 17px; }</style>\n' + '</head>\n') + '<body>';
@ -422,7 +421,8 @@ exports.getPadHTMLDocument = function (padId, revNum, noDocType, callback)
getPadHTML(pad, revNum, function (err, html) getPadHTML(pad, revNum, function (err, html)
{ {
callback(err, head + html + foot); if(ERR(err, callback)) return;
callback(null, head + html + foot);
}); });
}); });
} }

View file

@ -19,6 +19,7 @@
* limitations under the License. * limitations under the License.
*/ */
var ERR = require("async-stacktrace");
var settings = require('./Settings'); var settings = require('./Settings');
var async = require('async'); var async = require('async');
var fs = require('fs'); var fs = require('fs');
@ -77,7 +78,7 @@ exports.minifyJS = function(req, res, jsFilename)
//read the files in the folder //read the files in the folder
fs.readdir(path, function(err, files) fs.readdir(path, function(err, files)
{ {
if(err) { callback(err); return; } if(ERR(err, callback)) return;
//we wanna check the directory itself for changes too //we wanna check the directory itself for changes too
files.push("."); files.push(".");
@ -88,7 +89,7 @@ exports.minifyJS = function(req, res, jsFilename)
//get the stat data of this file //get the stat data of this file
fs.stat(path + "/" + filename, function(err, stats) fs.stat(path + "/" + filename, function(err, stats)
{ {
if(err) { callback(err); return; } if(ERR(err, callback)) return;
//get the modification time //get the modification time
var modificationTime = stats.mtime.getTime(); var modificationTime = stats.mtime.getTime();
@ -110,7 +111,11 @@ exports.minifyJS = function(req, res, jsFilename)
//check the modification time of the minified js //check the modification time of the minified js
fs.stat("../var/minified_" + jsFilename, function(err, stats) fs.stat("../var/minified_" + jsFilename, function(err, stats)
{ {
if(err && err.code != "ENOENT") callback(err); if(err && err.code != "ENOENT")
{
ERR(err, callback);
return;
}
//there is no minfied file or there new changes since this file was generated, so continue generating this file //there is no minfied file or there new changes since this file was generated, so continue generating this file
if((err && err.code == "ENOENT") || stats.mtime.getTime() < latestModification) if((err && err.code == "ENOENT") || stats.mtime.getTime() < latestModification)
@ -131,8 +136,9 @@ exports.minifyJS = function(req, res, jsFilename)
{ {
fs.readFile("../static/js/" + item, "utf-8", function(err, data) fs.readFile("../static/js/" + item, "utf-8", function(err, data)
{ {
if(ERR(err, callback)) return;
fileValues[item] = data; fileValues[item] = data;
callback(err); callback();
}); });
}, callback); }, callback);
}, },
@ -161,6 +167,8 @@ exports.minifyJS = function(req, res, jsFilename)
//read the included file //read the included file
fs.readFile(filename, "utf-8", function(err, data) fs.readFile(filename, "utf-8", function(err, data)
{ {
if(ERR(err, callback)) return;
//compress the file //compress the file
if(type == "JS") if(type == "JS")
{ {
@ -188,17 +196,19 @@ exports.minifyJS = function(req, res, jsFilename)
embeds[item] = embeds[item].substr(0, embeds[item].length-1); embeds[item] = embeds[item].substr(0, embeds[item].length-1);
embeds[item] = "'" + embeds[item] + "'"; embeds[item] = "'" + embeds[item] + "'";
callback(err); callback();
}); });
}, function(err) }, function(err)
{ {
if(ERR(err, callback)) return;
//replace the include command with the include //replace the include command with the include
for(var i in embeds) for(var i in embeds)
{ {
fileValues["ace.js"]=fileValues["ace.js"].replace(i, embeds[i]); fileValues["ace.js"]=fileValues["ace.js"].replace(i, embeds[i]);
} }
callback(err); callback();
}); });
}, },
//put all together and write it into a file //put all together and write it into a file
@ -227,7 +237,10 @@ exports.minifyJS = function(req, res, jsFilename)
if(os.type().indexOf("Windows") == -1) if(os.type().indexOf("Windows") == -1)
{ {
gzip(result, 9, function(err, compressedResult){ gzip(result, 9, function(err, compressedResult){
if(err) {callback(err); return} //weird gzip bug that returns 0 instead of null if everything is ok
err = err === 0 ? null : err;
if(ERR(err, callback)) return;
fs.writeFile("../var/minified_" + jsFilename + ".gz", compressedResult, callback); fs.writeFile("../var/minified_" + jsFilename + ".gz", compressedResult, callback);
}); });
@ -242,7 +255,10 @@ exports.minifyJS = function(req, res, jsFilename)
} }
], function(err) ], function(err)
{ {
if(err && err != "stop") throw err; if(err && err != "stop")
{
if(ERR(err)) return;
}
//check if gzip is supported by this browser //check if gzip is supported by this browser
var gzipSupport = req.header('Accept-Encoding', '').indexOf('gzip') != -1; var gzipSupport = req.header('Accept-Encoding', '').indexOf('gzip') != -1;
@ -270,15 +286,16 @@ exports.minifyJS = function(req, res, jsFilename)
async.forEach(jsFiles, function (item, callback) async.forEach(jsFiles, function (item, callback)
{ {
fs.readFile("../static/js/" + item, "utf-8", function(err, data) fs.readFile("../static/js/" + item, "utf-8", function(err, data)
{ {
if(ERR(err, callback)) return;
fileValues[item] = data; fileValues[item] = data;
callback(err); callback();
}); });
}, },
//send all files together //send all files together
function(err) function(err)
{ {
if(err) throw err; if(ERR(err)) return;
for(var i=0;i<jsFiles.length;i++) for(var i=0;i<jsFiles.length;i++)
{ {

View file

@ -10,17 +10,18 @@
"name": "Robin Buse"} "name": "Robin Buse"}
], ],
"dependencies" : { "dependencies" : {
"socket.io" : "0.8.7", "socket.io" : "0.8.7",
"ueberDB" : "0.1.3", "ueberDB" : "0.1.3",
"async" : "0.1.15", "async" : "0.1.15",
"joose" : "3.50.0", "joose" : "3.50.0",
"express" : "2.5.0", "express" : "2.5.0",
"clean-css" : "0.2.4", "clean-css" : "0.2.4",
"uglify-js" : "1.1.1", "uglify-js" : "1.1.1",
"gzip" : "0.1.0", "gzip" : "0.1.0",
"formidable" : "1.0.7", "formidable" : "1.0.7",
"log4js" : "0.3.9", "log4js" : "0.3.9",
"jsdom" : "0.2.9" "jsdom" : "0.2.9",
"async-stacktrace": "0.0.2"
}, },
"version" : "1.0.0" "version" : "1.0.0"
} }