No title Revision 363161623439 (Mon Aug 02 2010 at 10:01) - Diff Link to this snippet: https://friendpaste.com/4xckLZzYr4XSXhbAAGIBhj Embed: manni perldoc borland colorful default murphy trac fruity autumn bw emacs pastie friendly Show line numbers Wrap lines 1234567891011121314151617181920212223242526// failures maps failed save attempts to the error that caused them (validation, conflict, etc.)function(doc, req, failures) { var newDoc = doc || {_id: req.query.id || "example"}; if(!(newDoc._id in failures)) { // Legacy code does this now. It knows nothing about the failures argument, but // just blindly attempts a save. Possibilities: // 1. Successful save. Normal code path. // 2. Conflict or invalid. Erlang has 2 choices. // A. newDoc._id is not in failures; call me again with newDoc._id // added to the failures object. // B. newDoc._id is in failures. Erlang knows my code is naive or does // not know the new API; Same 409 Conflict as before. return [newDoc, "Attempting a smart save: " + newDoc._id + "\n"]; } else { var reason; if('validation' in failures[newDoc._id]) { reason = "Validation failure: " + JSON.stringify(failures[newDoc._id].validation); } else if ('conflict' in failures[newDoc._id]) { reason = "Document update conflict"; } else { reason = 'Unknown reason'; } return [null, "Sorry, this is not possible: " + reason + "\n"]; }}