Skip to content

Commit 18366f6

Browse files
committed
- also support pattern like lderror(1000, "message")
1 parent 341f2f9 commit 18366f6

5 files changed

Lines changed: 13 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Logs
22

3+
## v1.1.5
4+
5+
- also support pattern like `lderror(1000, "message")`
6+
7+
38
## v1.1.4
49

510
- return unknown lderror with unrecognized id.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ lderror contains an `id` field for identify what kind of error it is. to create
1010
new lderror("custom message", 1000);
1111
new lderror({message: "custom message", id: 1000});
1212
lderror(1000); /* auto new upon invocation */
13+
lderror(1002,"additional information")
1314
lderror("custom message"); /* by default, id will be 0 */
1415

1516
valid lderror object contains a field 'name' with value 'lderror', and an id field with values listed in `src/lde.ls`. Following demonstrates how to make a lderror-compatible error object with id 1000 by duck typing:

dist/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
import$(this, opt).id = opt.id || id || 0;
4646
} else if (typeof opt === 'number') {
4747
this.id = opt;
48+
if (typeof id === 'string') {
49+
this.message = id;
50+
}
4851
}
4952
if (!this.message) {
5053
this.message = idmap[this.id || 0] || idmap[0];

dist/index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lde.ls

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ lderror = (opt="", id = 0) ->
3535
delete opt.__proto__
3636
delete opt.constructor
3737
@ <<< opt <<< {id: opt.id or id or 0}
38-
else if typeof(opt) == \number => @id = opt
38+
else if typeof(opt) == \number =>
39+
@id = opt
40+
if typeof(id) == \string => @message = id
3941
if !(@message) => @message = idmap[@id or 0] or idmap.0
4042
@stack = (new Error!).stack
4143
# otherwise stringify wont keep the name

0 commit comments

Comments
 (0)