Comparing version 0.4.0 to 0.4.1
41
eraro.js
@@ -1,11 +0,10 @@ | ||
/* Copyright (c) 2014 Richard Rodger, MIT License */ | ||
/* Copyright (c) 2014-2015 Richard Rodger, MIT License */ | ||
/* jshint node:true, asi:true, eqnull:true */ | ||
// Create JavaScript Error objects with code strings, context details, and templated messages. | ||
// Create JavaScript Error objects with code strings, context details, | ||
// and templated messages. | ||
"use strict"; | ||
// #### System modules | ||
@@ -15,3 +14,2 @@ var util = require('util') | ||
// #### External modules | ||
@@ -21,3 +19,2 @@ var _ = require('lodash') | ||
// #### Exports | ||
@@ -27,4 +24,2 @@ module.exports = eraro | ||
// #### Create an _eraro_ function | ||
@@ -79,3 +74,3 @@ // Parameters: | ||
if( util.isError(ex) ) { | ||
if( ex.eraro ) return ex; | ||
if( ex.eraro && !options.override ) return ex; | ||
} | ||
@@ -90,3 +85,3 @@ else { | ||
code = _.isString(code) ? code : | ||
code = _.isString(code) ? code : | ||
(ex ? | ||
@@ -101,3 +96,3 @@ ex.code ? ex.code : | ||
msg = _.isString(msg) ? msg : null | ||
msg = buildmessage(msg,msgmap,msgprefix,inspect,code,details,ex) | ||
msg = buildmessage(options,msg,msgmap,msgprefix,inspect,code,details,ex) | ||
@@ -196,6 +191,6 @@ | ||
// Returns: String; human readable error message | ||
function buildmessage(msg,msgmap,msgprefix,inspect,code,details,ex) { | ||
function buildmessage(options,msg,msgmap,msgprefix,inspect,code,details,ex) { | ||
var message = msgprefix + (_.isString(msg) ? msg : | ||
_.isString(msgmap[code]) ? msgmap[code] : | ||
(ex ? ex.message : code) ) | ||
ex ? originalmsg(options.override,ex) : code ) | ||
@@ -205,4 +200,5 @@ // These are the inserts. | ||
// Workaround to prevent underscore blowing up if properties are not found. | ||
// Reserved words and undefined need to be suffixed with $ in the template interpolates. | ||
// Workaround to prevent underscore blowing up if properties are not | ||
// found. Reserved words and undefined need to be suffixed with $ | ||
// in the template interpolates. | ||
@@ -233,6 +229,8 @@ var valstrmap = {util:util,_:_} | ||
// Some other error - give up and just dump the properties at the end of the template. | ||
// Some other error - give up and just dump the properties at | ||
// the end of the template. | ||
else { | ||
done = true | ||
message = message+' VALUES:'+util.inspect(valmap,{depth:2})+' TEMPLATE ERROR: '+e | ||
message = message+' VALUES:'+util.inspect(valmap,{depth:2})+ | ||
' TEMPLATE ERROR: '+e | ||
} | ||
@@ -245,1 +243,10 @@ } | ||
function originalmsg( override, ex ) { | ||
if( !ex ) return; | ||
if( override && ex.eraro && ex.orig ) return ex.orig.message; | ||
return ex.message; | ||
} |
{ | ||
"name": "eraro", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Create JavaScript Error objects with code strings, context details, and templated messages.", | ||
"main": "eraro.js", | ||
"scripts": { | ||
"test": "node test/eraro.test.js", | ||
"jshint": "./node_modules/.bin/jshint eraro.js", | ||
"docco": "./node_modules/.bin/docco eraro.js -o doc", | ||
"gh-pages-doc": "cp -r doc/* ../gh-pages/eraro/doc" | ||
"test": "./test.sh", | ||
"build": "./build.sh" | ||
}, | ||
@@ -18,3 +16,4 @@ "repository": { | ||
"eraro", | ||
"error" | ||
"error", | ||
"exception" | ||
], | ||
@@ -30,7 +29,2 @@ "author": "Richard Rodger (http://richardrodger.com)", | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.20.1", | ||
"docco": "~0.6.3", | ||
"jshint": "~2.5.10" | ||
}, | ||
"files": [ | ||
@@ -37,0 +31,0 @@ "README.md", |
@@ -6,4 +6,10 @@ eraro | ||
There is [annotated source code](http://rjrodger.github.io/eraro/doc/eraro.html) for this module. | ||
Current Version: 0.4.1 | ||
Tested on: node 0.10.35 | ||
[![Build Status](https://travis-ci.org/rjrodger/eraro.png?branch=master)](https://travis-ci.org/rjrodger/eraro) | ||
[Annotated Source](http://rjrodger.github.io/eraro/doc/eraro.html) | ||
For use in library modules to generate contextual errors with useful | ||
@@ -15,5 +21,13 @@ meta data. Your library module can throw or pass (to a callback) an | ||
See the [use-plugin](http://github.com/rjrodger/use-plugin) module for an example of practical usage. | ||
See the [use-plugin](http://github.com/rjrodger/use-plugin) module for | ||
an example of practical usage. | ||
# Support | ||
If you're using this module, feel free to contact me on twitter if you have any questions! :) [@rjrodger](http://twitter.com/rjrodger) | ||
[![Gitter chat](https://badges.gitter.im/rjrodger/eraro.png)](https://gitter.im/rjrodger/eraro) | ||
# Quick example | ||
@@ -39,3 +53,4 @@ | ||
In all these cases, the Error object will have a _code_ property with value _"code_string"_. | ||
In all these cases, the Error object will have a _code_ property with | ||
value _"code_string"_. | ||
@@ -170,15 +185,5 @@ | ||
* _[use-plugin](http://github.com/rjrodger/use-plugin)_: a utility for providing a plugin interface for extensions to your module | ||
* _[seneca](http://github.com/rjrodger/seneca)_: a micro-services framework for Node.js | ||
# Support | ||
If you're using this module, feel free to contact me on twitter if you have any questions! :) [@rjrodger](http://twitter.com/rjrodger) | ||
Current Version: 0.4.0 | ||
Tested on: node 0.10.35 | ||
[![Build Status](https://travis-ci.org/rjrodger/eraro.png?branch=master)](https://travis-ci.org/rjrodger/eraro) | ||
[Annotated Source](http://rjrodger.github.io/eraro/doc/eraro.html) | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13599
0
188
186