Permalink
Browse files

First commit

  • Loading branch information...
1 parent b5fe7bc commit b63deaf73ef796e61ec6ae6bee7dfeee35bfb7e4 @FGRibreau committed Dec 31, 2012
Showing with 206 additions and 3 deletions.
  1. +1 −0 .npmignore
  2. +4 −0 .travis.yml
  3. +22 −0 LICENSE-MIT
  4. +37 −3 README.md
  5. +39 −0 grunt.js
  6. +17 −0 lib/index.js
  7. +31 −0 package.json
  8. +55 −0 test/callstack-cleaner_test.js
View
@@ -0,0 +1 @@
+/node_modules/
View
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+ - 0.6
+ - 0.8
View
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Francois-Guillaume Ribreau <npm@fgribreau.com> (http://fgribreau.com)
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,4 +1,38 @@
-node-callstack-cleaner
-======================
+Callstack-cleaner [![Build Status](https://secure.travis-ci.org/FGRibreau/node-callstack-cleaner.png)](https://secure.travis-ci.org/FGRibreau/node-callstack-cleaner)
+==========
+Clean the callstack from error messages
-Clean callstack from error message (see use-cases in Readme)
+## Getting Started
+Install the module with: `npm install callstack-cleaner`
+
+```javascript
+var callstack_cleaner = require('callstack-cleaner');
+
+var _err = new Error("plop");
+var err = new Error("Redis reply parser error: " + _err.stack); // see `Why` section
+
+err = callstack_cleaner(err); // "Redis reply parser error: Error: plop"
+```
+
+## Why ??
+node_redis emit parser error in a weird way:
+```javascript
+// https://github.com/mranney/node_redis/blob/c3ea30ebea7b9eddba3534fcd357e3ec04fd9683/index.js#L267
+
+this.reply_parser.on("error", function (err) {
+ self.emit("error", new Error("Redis reply parser error: " + err.stack));
+});
+```
+
+Callstack-cleaner remove the callstack from the emitted `error.message`.
+
+## Contributing
+In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt](https://github.com/cowboy/grunt).
+
+## Release History
+### v0.1.0
+Initial version.
+
+## License
+Copyright (c) 2012 Francois-Guillaume Ribreau <npm@fgribreau.com> (http://fgribreau.com)
+Licensed under the MIT license.
View
@@ -0,0 +1,39 @@
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ pkg: '<json:package.json>',
+ test: {
+ files: ['test/**/*.js']
+ },
+ lint: {
+ files: ['grunt.js', 'lib/**/*.js', 'test/**/*.js']
+ },
+ watch: {
+ files: '<config:lint.files>',
+ tasks: 'default'
+ },
+ jshint: {
+ options: {
+ curly: true,
+ eqeqeq: true,
+ immed: true,
+ latedef: true,
+ newcap: true,
+ noarg: true,
+ sub: true,
+ undef: true,
+ boss: true,
+ eqnull: true,
+ node: true
+ },
+ globals: {
+ exports: true
+ }
+ }
+ });
+
+ // Default task.
+ grunt.registerTask('default', 'lint test');
+
+};
View
@@ -0,0 +1,17 @@
+/*
+ * callstack-cleaner
+ * https://github.com/FGRibreau/node-callstack-cleaner
+ *
+ * Copyright (c) 2012 Francois-Guillaume Ribreau <npm@fgribreau.com> (http://fgribreau.com)
+ * Licensed under the MIT license.
+ */
+
+module.exports = function(err) {
+ if(err instanceof Error){
+ err = err.message;
+ }
+
+ return err.split('\n').filter(function(line){
+ return line.trim().indexOf('at') !== 0;
+ }).join('\n');
+};
View
@@ -0,0 +1,31 @@
+{
+ "name": "callstack-cleaner",
+ "description": "Clean the callstack from error messages",
+ "version": "0.1.0",
+ "homepage": "https://github.com/FGRibreau/node-callstack-cleaner",
+ "author": "Francois-Guillaume Ribreau <npm@fgribreau.com> (http://fgribreau.com)",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/FGRibreau/node-callstack-cleaner.git"
+ },
+ "bugs": {
+ "url": "https://github.com/FGRibreau/node-callstack-cleaner/issues"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "https://github.com/FGRibreau/node-callstack-cleaner/blob/master/LICENSE-MIT"
+ }
+ ],
+ "main": "lib/index",
+ "engines": {
+ "node": ">= 0.6.0"
+ },
+ "scripts": {
+ "test": "grunt test"
+ },
+ "devDependencies": {
+ "grunt": "~0.3.15"
+ },
+ "keywords": ["callstack", "error"]
+}
@@ -0,0 +1,55 @@
+var callstack_cleaner = require('../lib/index.js');
+
+/*
+ ======== A Handy Little Nodeunit Reference ========
+ https://github.com/caolan/nodeunit
+
+ Test methods:
+ test.expect(numAssertions)
+ test.done()
+ Test assertions:
+ test.ok(value, [message])
+ test.equal(actual, expected, [message])
+ test.notEqual(actual, expected, [message])
+ test.deepEqual(actual, expected, [message])
+ test.notDeepEqual(actual, expected, [message])
+ test.strictEqual(actual, expected, [message])
+ test.notStrictEqual(actual, expected, [message])
+ test.throws(block, [error], [message])
+ test.doesNotThrow(block, [error], [message])
+ test.ifError(value)
+*/
+
+exports['callstack-cleaner'] = {
+ setUp: function(done) {
+ done();
+ },
+ 'handles empty string': function(t){
+ var s = "";
+ t.equal(callstack_cleaner(s), s);
+ t.done();
+ },
+ 'handles string': function(t){
+ var s = "bla bla\nblabla";
+ t.equal(callstack_cleaner(s), s);
+ t.done();
+ },
+ 'handles empty error object': function(t){
+ var s = "";
+ t.equal(callstack_cleaner(new Error(s)), s);
+ t.done();
+ },
+ 'handle error object': function(t){
+ var s = "bla bla\nblabla";
+ t.equal(callstack_cleaner(new Error(s)), s);
+ t.done();
+ },
+ 'with callstack inside error message': function(t){
+ // Extracted from node_redis
+ // https://github.com/mranney/node_redis/blob/c3ea30ebea7b9eddba3534fcd357e3ec04fd9683/index.js#L267
+ var _err = new Error("plop");
+ var err = new Error("Redis reply parser error: " + _err.stack);
+ t.equal(callstack_cleaner(err), "Redis reply parser error: Error: plop");
+ t.done();
+ }
+};

0 comments on commit b63deaf

Please sign in to comment.