Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
E.Azer Koçulu committed Mar 13, 2014
0 parents commit 0b059ff
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
4 changes: 4 additions & 0 deletions .npmignore
@@ -0,0 +1,4 @@
test
test.js
example
examples
22 changes: 22 additions & 0 deletions README.md
@@ -0,0 +1,22 @@
## failing-line

Return the line number and filename of failing line from given error object

## Install

```bash
$ npm install failing-line
```

## Usage

```js
var failingLine = require('failing-line')

process.on('uncaughtException', function (error) {
failingLine(error)
// => { lineno: 8, filename: 'example.js' }
})

hereIfail++
```
13 changes: 13 additions & 0 deletions index.js
@@ -0,0 +1,13 @@
module.exports = failingLine;

function failingLine (error) {
var match = error.stack.match(/\(([^\(\)]+)\)/);
if (!match) return undefined;

match = match[1].split(':');

return {
filename: match[0],
lineno: Number(match[1])
};
}
24 changes: 24 additions & 0 deletions package.json
@@ -0,0 +1,24 @@
{
"name": "failing-line",
"version": "0.0.0",
"description": "Return the line number and filename of failing line from given error object",
"main": "index.js",
"scripts": {
"test": "node test.js"
},
"devDependencies": {
"tape": "*"
},
"keywords": [
"error",
"fail",
"failing",
"line number"
],
"repository": {
"url": "git@github.com:azer\/failing-line.git",
"type": "git"
},
"author": "azer",
"license": "BSD"
}
11 changes: 11 additions & 0 deletions test.js
@@ -0,0 +1,11 @@
var failingLine = require("./");
var test = require("tape");

test('failing line', function (assert) {
var err = new Error('Hello World');
var ln = failingLine(err);

assert.equal(ln.lineno, 5);
assert.equal(ln.filename, __filename);
assert.end();
});

0 comments on commit 0b059ff

Please sign in to comment.