Skip to content

Commit 67c7641

Browse files
committed
Improve error messaging when unable to find @Package
Fixes #6
1 parent f824863 commit 67c7641

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; Unix-style newlines
2+
[*]
3+
end_of_line = LF
4+
indent_style = tab
5+
indent_size = 4
6+
7+
[{*.json,*.yml,*.md}]
8+
indent_style = space
9+
indent_size = 2

package.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,53 @@ var fs = require("graceful-fs");
44
/**
55
* @parent bit-docs-tag-package/tags
66
* @module {bit-docs-process-tags/types/tag} bit-docs-tag-package/tags/package @package
7-
*
7+
*
88
* @description Adds the package's `package.json` info to the
99
* [bit-docs/types/docObject].
10-
*
10+
*
1111
* @signature `@package PATH`
12-
*
12+
*
1313
* Once added to the [bit-docs/types/docObject], you can reference the
1414
* `package.json` properties like `name`, `description`, `author`, etc in
1515
* `.mustache` templates.
16-
*
16+
*
1717
* @param {String} PATH The path to a `package.json` file.
18-
*
18+
*
1919
* @body
20-
*
20+
*
2121
* An example `package.json` file might look like:
22-
*
22+
*
2323
* ```js
2424
* {
2525
* "name": "my-package",
2626
* "version": "0.0.1",
2727
* "description": "My cool package.",
2828
* }
2929
* ```
30-
*
30+
*
3131
* That gets used like:
32-
*
32+
*
3333
* ```js
3434
* @@package ./demos/package.json
3535
* ```
3636
*/
3737
module.exports = {
3838
add: function(line, curData, scope, objects, currentWrite) {
39-
var pkgPath = path.join(path.dirname(this.src.path), line.replace("@package", "").trim());
40-
var pkg = fs.readFileSync(pkgPath).toString();
39+
var atPackagePath = line.replace("@package", "").trim();
40+
var pkgPath = path.join(path.dirname(this.src.path), atPackagePath);
41+
var pkg;
42+
try {
43+
pkg = fs.readFileSync(pkgPath).toString();
44+
} catch(e) {
45+
if(e.code === "ENOENT") {
46+
var newError = new Error('@package: Unable to locate ' +
47+
atPackagePath + " from " + this.src.path
48+
);
49+
throw newError;
50+
}
51+
52+
throw e;
53+
}
4154
var result = JSON.parse(pkg);
4255

4356
// delete things that would be too big

0 commit comments

Comments
 (0)