diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-04-13 18:40:35 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-04-14 08:46:54 +0000 |
| commit | 1a8debe87762072b3a63b769aa515ebf63b4c70d (patch) | |
| tree | 33b42866307d11d2c0878b23e0ec0bb8925d3fcc /core/error.moon | |
| parent | spec base.match __tostring (diff) | |
| download | alive-1a8debe87762072b3a63b769aa515ebf63b4c70d.tar.gz alive-1a8debe87762072b3a63b769aa515ebf63b4c70d.zip | |
move into proper Lua module (`alv`)
Diffstat (limited to 'core/error.moon')
| -rw-r--r-- | core/error.moon | 94 |
1 files changed, 0 insertions, 94 deletions
diff --git a/core/error.moon b/core/error.moon deleted file mode 100644 index e72cc5f..0000000 --- a/core/error.moon +++ /dev/null @@ -1,94 +0,0 @@ ----- --- Language error and traceback. --- --- @classmod Error - -unpack or= table.unpack - -class Error ---- members --- @section members - - --- append a traceback frame. - -- - -- `where` should denote where the Error occured and fit grammatically to - -- complete the sentence `"{error} occured while {where}"` - -- - -- @tparam string where - add_frame: (where) => @trace ..= "\n while #{where}" - - __tostring: => - str = "#{@kind} error: #{@message}" - if @detail - str ..= "\n#{@detail}" - if @trace - str ..= @trace - str - ---- static functions --- @section static - - --- create a new Error. - -- - -- `kind` should be one of: - -- - -- - `'reference'`: error concerning symbol resolution - -- - `'argument'`: error concerning Op argument matching - -- - `'implementation'`: error in the Lua/MoonScript implementation of alive. - -- Should not occur in normal operation, and constitutes a bug. - -- - -- @classmethod - -- @tparam string kind - -- @tparam string message - -- @tparam ?string detail - new: (@kind, @message, @detail) => - @trace = '' - - handler = (err) -> - if err.__class == Error - err - else - Error 'implementation', err, debug.traceback "Lua error below:", 2 - --- Wrap function errors in a traceback frame. - -- - -- Execute `fn(...)`, and turn any error thrown as a result into an - -- `Error` instance, before re-throwing it. - -- - -- When `Error` instances are caught, `frame` is added to the traceback. - -- All other error values are turned into `'implementation'` Errors. - -- - -- @tparam string frame - -- @tparam function fn - @wrap: (frame, fn, ...) -> - results = { xpcall fn, handler, ... } - ok = table.remove results, 1 - if ok - unpack results - else - error with results[1] - \add_frame frame - - --- Capture and wrap function errors in traceback frame. - -- - -- Execute `fn(...)`, and turn any error thrown as a result into an - -- `Error` instance, before re-throwing it. - -- - -- When `Error` instances are caught, `frame` is added to the traceback. - -- All other error values are turned into `'implementation'` Errors. - -- - -- @tparam string frame - -- @tparam function fn - -- @treturn boolean `ok` true if exeuction suceeded without errors - -- @treturn Error|any `error_or_results` the `Error` instance or results - @try: (frame, fn, ...) -> - results = { xpcall fn, handler, ... } - ok = table.remove results, 1 - if ok - ok, unpack results - else - ok, with results[1] - \add_frame frame - -{ - :Error -} |
