IcedErrors
An integrated error system for dealing with errors, written for and with IcedCoffeeScript. I found myself doing this stuff everytime I wrote a new project, so better to standardize it.
Enumerated Error Types
In your lib/error.iced
file:
require 'iced-error'exports.E = make_errors NOT_FOUND : "Requested resource was not found" BAD_MAC : "MAC failed on header" INVAL : "Invalid value" DB_INSERT : "Error inserting into the database"
In your foo.iced
file:
require './lib/error' consolelog EOK # prints 0 consolelog ENOT_FOUND # prints 100 consolelog EmsgENOT_FOUND# prints "Requested resource was not found" consolelog EmsgNOT_FOUND# prints "Requested resource was not found" consolelog EnameNOT_FOUND # prints "NOT_FOUND" consolelog EnameENOT_FOUND# prints "NOT_FOUND"
You can also use predefined Error classes:
require './lib/error' # You can throw these errors too throw "your file" # Will print [NotFoundError: your file (code 100)] consolelog "your file" # Will print "your file" consolelog "your file"message # Will print 100 consolelog "your file"code
Error Short Circuiters
Catch errors all at once, not everywhere!
require 'iced-error'= esc = make_esc gcb"my_fn" await socketget 'image id'esc defer id await ImagefindById idesc defer image await check_permissions userimageesc defer permitted gcb nullimage