Skip to content

Commit

Permalink
Merge pull request #8 from pugjs/pug
Browse files Browse the repository at this point in the history
Rename to pug-error
  • Loading branch information
ForbesLindesay committed Dec 23, 2015
2 parents 14bafda + 61311c4 commit f9da0bc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# jade-error
# pug-error

Standard error objects for jade. This module is intended for use by the lexer, parser, loader, linker, code-generator and any plugins.
Standard error objects for pug. This module is intended for use by the lexer, parser, loader, linker, code-generator and any plugins.

[![Build Status](https://img.shields.io/travis/jadejs/jade-error/master.svg)](https://travis-ci.org/jadejs/jade-error)
[![Dependency Status](https://img.shields.io/gemnasium/jadejs/jade-error.svg)](https://gemnasium.com/jadejs/jade-error)
[![NPM version](https://img.shields.io/npm/v/jade-error.svg)](https://www.npmjs.org/package/jade-error)
[![Build Status](https://img.shields.io/travis/pugjs/pug-error/master.svg)](https://travis-ci.org/pugjs/pug-error)
[![Dependency Status](https://img.shields.io/gemnasium/pugjs/pug-error.svg)](https://gemnasium.com/pugjs/pug-error)
[![NPM version](https://img.shields.io/npm/v/pug-error.svg)](https://www.npmjs.org/package/pug-error)

## Installation

npm install jade-error
npm install pug-error

## Usage

```js
var error = require('jade-error');
var error = require('pug-error');
```

### `error(code, message, options)`

Create a Jade error object.
Create a Pug error object.

`code` is a required unique code for the error type that can be used to pinpoint a certain error.

Expand All @@ -29,17 +29,17 @@ Create a Jade error object.
- `filename`: the name of the file causing the error
- `line`: the offending line
- `column`: the offending column
- `src`: the Jade source, if available, for pretty-printing the error context
- `src`: the Pug source, if available, for pretty-printing the error context

The resulting error object is a simple Error object with additional properties given in the arguments.

**Caveat:** the `message` argument is stored in `err.msg`, not `err.message`, which is occupied with a better-formatted message.

```js
var error = require('jade-error');
var error = require('pug-error');

var err = error('MY_CODE', 'My message', {line: 3, filename: 'myfile', src: 'foo\nbar\nbaz\nbash\nbing'});
// { code: 'JADE:MY_CODE',
// { code: 'PUG:MY_CODE',
// msg: 'My message',
// line: 3,
// column: undefined,
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ function makeError(code, message, options) {
}
return out;
}).join('\n');
fullMessage = (filename || 'Jade') + ':' + location + '\n' + context + '\n\n' + message;
fullMessage = (filename || 'Pug') + ':' + location + '\n' + context + '\n\n' + message;
} else {
fullMessage = (filename || 'Jade') + ':' + location + '\n\n' + message;
fullMessage = (filename || 'Pug') + ':' + location + '\n\n' + message;
}
var err = new Error(fullMessage);
err.code = 'JADE:' + code;
err.code = 'PUG:' + code;
err.msg = message;
err.line = line;
err.column = column;
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "jade-error",
"name": "pug-error",
"version": "1.2.0",
"description": "Standard error objects for jade",
"description": "Standard error objects for pug",
"keywords": [
"jade"
"pug"
],
"files": [
"index.js"
Expand All @@ -18,7 +18,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/jadejs/jade-error.git"
"url": "https://github.com/pugjs/pug-error.git"
},
"author": "Forbes Lindesay",
"license": "MIT"
Expand Down
18 changes: 9 additions & 9 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ test('with a source', function () {
test('and a filename', function () {
var err = error('MY_CODE', 'My message', {line: 3, filename: 'myfile', src: 'foo\nbar\nbaz\nbash\nbing'});
assert(err.message === 'myfile:3\n 1| foo\n 2| bar\n > 3| baz\n 4| bash\n 5| bing\n\nMy message');
assert(err.code === 'JADE:MY_CODE');
assert(err.code === 'PUG:MY_CODE');
assert(err.msg === 'My message');
assert(err.line === 3);
assert(err.filename === 'myfile');
assert(err.src === 'foo\nbar\nbaz\nbash\nbing');
});
test('and no filename', function () {
var err = error('MY_CODE', 'My message', {line: 3, src: 'foo\nbar\nbaz\nbash\nbing'});
assert(err.message === 'Jade:3\n 1| foo\n 2| bar\n > 3| baz\n 4| bash\n 5| bing\n\nMy message');
assert(err.code === 'JADE:MY_CODE');
assert(err.message === 'Pug:3\n 1| foo\n 2| bar\n > 3| baz\n 4| bash\n 5| bing\n\nMy message');
assert(err.code === 'PUG:MY_CODE');
assert(err.msg === 'My message');
assert(err.line === 3);
assert(err.filename === undefined);
Expand All @@ -29,16 +29,16 @@ test('without source', function () {
test('and with a filename', function () {
var err = error('MY_CODE', 'My message', {line: 3, filename: 'myfile'});
assert(err.message === 'myfile:3\n\nMy message');
assert(err.code === 'JADE:MY_CODE');
assert(err.code === 'PUG:MY_CODE');
assert(err.msg === 'My message');
assert(err.line === 3);
assert(err.filename === 'myfile');
assert(err.src === undefined);
});
test('and with no filename', function () {
var err = error('MY_CODE', 'My message', {line: 3});
assert(err.message === 'Jade:3\n\nMy message');
assert(err.code === 'JADE:MY_CODE');
assert(err.message === 'Pug:3\n\nMy message');
assert(err.code === 'PUG:MY_CODE');
assert(err.msg === 'My message');
assert(err.line === 3);
assert(err.filename === undefined);
Expand All @@ -50,16 +50,16 @@ test('with column', function () {
test('and with a filename', function () {
var err = error('MY_CODE', 'My message', {line: 3, column: 2, filename: 'myfile', src: 'foo\nbar\nbaz\nbash\nbing'});
assert(err.message === 'myfile:3:2\n 1| foo\n 2| bar\n > 3| baz\n--------^\n 4| bash\n 5| bing\n\nMy message');
assert(err.code === 'JADE:MY_CODE');
assert(err.code === 'PUG:MY_CODE');
assert(err.msg === 'My message');
assert(err.line === 3);
assert(err.filename === 'myfile');
assert(err.src === 'foo\nbar\nbaz\nbash\nbing');
});
test('and with no filename', function () {
var err = error('MY_CODE', 'My message', {line: 3, column: 1});
assert(err.message === 'Jade:3:1\n\nMy message');
assert(err.code === 'JADE:MY_CODE');
assert(err.message === 'Pug:3:1\n\nMy message');
assert(err.code === 'PUG:MY_CODE');
assert(err.msg === 'My message');
assert(err.line === 3);
assert(err.filename === undefined);
Expand Down

0 comments on commit f9da0bc

Please sign in to comment.