diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-03-02 11:41:42 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-03-02 11:41:42 +0000 |
| commit | 195134a09b0b37c2c371a9f1a17314996a591bcb (patch) | |
| tree | 1eaadb7cd127944b48afb740f5f988644d563f21 | |
| parent | IO system (diff) | |
| download | alive-195134a09b0b37c2c371a9f1a17314996a591bcb.tar.gz alive-195134a09b0b37c2c371a9f1a17314996a591bcb.zip | |
log errors differently
| -rw-r--r-- | copilot.moon | 21 | ||||
| -rw-r--r-- | logger.moon | 9 |
2 files changed, 16 insertions, 14 deletions
diff --git a/copilot.moon b/copilot.moon index a66c570..1791174 100644 --- a/copilot.moon +++ b/copilot.moon @@ -22,28 +22,21 @@ class Copilot error "not a file: #{@file}" patch: => - ast, err = parse slurp @file - - if not ast - L\error "error parsing: #{err}" - return + ast = L\try "error parsing:", parse, slurp @file + return unless ast scope = Scope ast, globals - ok, err = pcall ast\eval, scope, @registry - if not ok - L\error "error evaluating: #{err}" - return + root = L\try "error evaluating:", ast\eval, scope, @registry + return unless root - @root = err + @root = root if root ast tick: => @poll! if @root - ok, err = pcall @registry\wrap_tick @root\tick - if not ok - L\error err + L\try "error evaluating:", @registry\wrap_tick @root\tick tb = (msg) -> debug.traceback msg, 2 poll: => @@ -54,7 +47,7 @@ class Copilot if @last_modification < modification L\log "#{@file} changed at #{modification}" ast = L\push @registry\wrap_eval @\patch - spit @file, ast\stringify! + spit @file, ast\stringify! if ast @last_modification = os.time! :Copilot diff --git a/logger.moon b/logger.moon index e1d6611..97b3c0d 100644 --- a/logger.moon +++ b/logger.moon @@ -48,6 +48,15 @@ class Logger else error unpack res + try: (msg, fn, ...) => + ok, err = xpcall fn, debug.traceback, ... + + if not ok + @error msg, err + + if ok then err + +-- static init: (...) -> export L L = Logger ... |
