• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

LICENSED24-Sep-20231 KiB1916

README.mdD24-Sep-20231.7 KiB5636

index.jsD24-Sep-20231.4 KiB5047

package.jsonD24-Sep-2023386 1918

README.md

1# pug-error
2
3Standard error objects for pug.  This module is intended for use by the lexer, parser, loader, linker, code-generator and any plugins.
4
5[![Build Status](https://img.shields.io/travis/pugjs/pug-error/master.svg)](https://travis-ci.org/pugjs/pug-error)
6[![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug-error)](https://david-dm.org/pugjs/pug?path=packages/pug-error)
7[![NPM version](https://img.shields.io/npm/v/pug-error.svg)](https://www.npmjs.org/package/pug-error)
8
9## Installation
10
11    npm install pug-error
12
13## Usage
14
15```js
16var error = require('pug-error');
17```
18
19### `error(code, message, options)`
20
21Create a Pug error object.
22
23`code` is a required unique code for the error type that can be used to pinpoint a certain error.
24
25`message` is a human-readable explanation of the error.
26
27`options` can contain any of the following properties:
28
29- `filename`: the name of the file causing the error
30- `line`: the offending line
31- `column`: the offending column
32- `src`: the Pug source, if available, for pretty-printing the error context
33
34The resulting error object is a simple Error object with additional properties given in the arguments.
35
36**Caveat:** the `message` argument is stored in `err.msg`, not `err.message`, which is occupied with a better-formatted message.
37
38```js
39var error = require('pug-error');
40
41var err = error('MY_CODE', 'My message', {line: 3, filename: 'myfile', src: 'foo\nbar\nbaz\nbash\nbing'});
42// { code: 'PUG:MY_CODE',
43//   msg: 'My message',
44//   line: 3,
45//   column: undefined,
46//   filename: 'myfile',
47//   src: 'foo\nbar\nbaz\nbash\nbing',
48//   message: 'myfile:3\n    1| foo\n    2| bar\n  > 3| baz\n    4| bash\n    5| bing\n\nMy message' }
49
50throw err;
51```
52
53## License
54
55  MIT
56