~technomancy/fennel#164: 
,reload should report reloading errors via the on-error callback

Right now the ,reload command upon re-requering the module returns errors via the on-values callback:

(let [_ (tset package.loaded module-name nil)
      (ok new) (pcall require module-name)
      ;; keep the old module if reload failed
      new (if (not ok)
              (do
                (on-values [new]) ; should be on-error here?
                old)
              new)]
  ...)

This causes the problem that if the REPL defines a custom on-error handler, it completely misses this error.

I guess this is done because the error from require is already composed, e.g. it already contains the full message, which makes it hard to pass it to the on-error which builds this kind of message from its arguments. We can decompose the message, but it seems to be error-prone if the message format changes. Alternatively, require can be made to return errors in an unformatted way if an optional second argument is provided, but this looks like a lot of changes in the compiler, and we still probably can't control runtime errors coming from Lua itself (correct me if I'm wrong).

Status
RESOLVED IMPLEMENTED
Submitter
~andreyorst
Assigned to
No-one
Submitted
1 year, 3 months ago
Updated
2 months ago
Labels
enhancement

~technomancy REPORTED IMPLEMENTED 2 months ago

I think the naive approach here is fine; if something gets double-wrapped it's still better than reporting it as a value.

Fixed in d808246.

Register here or Log in to comment, or comment via email.