~technomancy/fennel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 3

[PATCH fennel v2] Add an error message to fennel.searcher

Details
Message ID
<20220105050724.174804-1-xordspar0@gmail.com>
DKIM signature
pass
Download raw message
Patch: +29 -6
This adds the paths that Fennel checked to the error output if a module
is not found:

    >> (require :nope)
    runtime error: module 'nope' not found:
    	no field package.preload['nope']
    	no file '/usr/local/share/lua/5.3/nope.lua'
    	no file '/usr/local/share/lua/5.3/nope/init.lua'
    	...
    	no file './nope.fnl'
    	no file './nope/init.fnl'
---
This revision fixes inconsistencies between Lua versions and adds a test.

 src/fennel/specials.fnl | 23 ++++++++++++++++++-----
 test/init.lua           |  3 ++-
 test/searcher.fnl       |  9 +++++++++
 3 files changed, 29 insertions(+), 6 deletions(-)
 create mode 100644 test/searcher.fnl

diff --git a/src/fennel/specials.fnl b/src/fennel/specials.fnl
index 8e0b3b6..aaad502 100644
--- a/src/fennel/specials.fnl
+++ b/src/fennel/specials.fnl
@@ -1027,17 +1027,29 @@ Only works in Lua 5.3+ or LuaJIT with the --use-bit-lib flag.")
        (match (or (io.open filename) (io.open filename2))
          file (do
                 (file:close)
                 filename))))
                 filename)
          _ (values nil (.. "no file '" filename "'")))))

    (fn find-in-path [start]
    (fn find-in-path [start ?tried-paths]
      (match (fullpath:match pattern start)
        path (or (try-path path) (find-in-path (+ start (length path) 1)))))
        path (match (try-path path)
          filename filename
          (nil error) (find-in-path (+ start (length path) 1)
                                    (doto (or ?tried-paths []) (table.insert error))))
        _ (values nil
                  ;; Before Lua 5.4 it was necessary to prepend a \n\t to the
                  ;; error message. In newer versions doing so causes an empty
                  ;; line before Fennel's error message.
                  (let [tried-paths (table.concat (or ?tried-paths []) "\n\t")]
                    (if (< _VERSION "Lua 5.4")
                      (.. "\n\t" tried-paths)
                      tried-paths)))))

    (find-in-path 1)))

(fn make-searcher [?options]
  "This will allow regular `require` to work with Fennel:
table.insert(package.loaders, fennel.searcher)"
table.insert(package.loaders or package.searchers, fennel.searcher)"
  (fn [module-name]
    (let [opts (utils.copy utils.root.options)]
      (each [k v (pairs (or ?options {}))]
@@ -1045,7 +1057,8 @@ table.insert(package.loaders, fennel.searcher)"
      (set opts.module-name module-name)
      (match (search-module module-name)
        filename (values (partial utils.fennel-module.dofile filename opts)
                         filename)))))
                         filename)
        (nil error) error))))

(fn fennel-macro-searcher [module-name]
  (let [opts (doto (utils.copy utils.root.options)
diff --git a/test/init.lua b/test/init.lua
index 73f7777..8124b29 100644
--- a/test/init.lua
+++ b/test/init.lua
@@ -32,7 +32,8 @@ local function testall(suites)
end

local suites = {"core", "mangling", "quoting", "bit", "fennelview", "parser",
                "failures", "repl", "cli", "macro", "linter", "loops", "misc"}
                "failures", "repl", "cli", "macro", "linter", "loops", "misc",
                "searcher"}

if(#arg == 0) then
   local ok, err = pcall(testall, suites)
diff --git a/test/searcher.fnl b/test/searcher.fnl
new file mode 100644
index 0000000..818b9b8
--- /dev/null
+++ b/test/searcher.fnl
@@ -0,0 +1,9 @@
(local l (require :test.luaunit))
(local fennel (require :fennel))

(fn test-searcher-error-contains-fnl-files []
  (let [(ok error) (pcall require :notreal)]
    (l.assertEquals ok false)
    (l.assertEquals (string.match error :notreal.fnl) :notreal.fnl)))

{: test-searcher-error-contains-fnl-files}
-- 
2.32.0

[fennel/patches/.build.yml] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CGXHB2E01FLK.1THA4R5XRKJ92@cirno>
In-Reply-To
<20220105050724.174804-1-xordspar0@gmail.com> (view parent)
DKIM signature
missing
Download raw message
fennel/patches/.build.yml: SUCCESS in 32s

[Add an error message to fennel.searcher][0] v2 from [Jordan Christiansen][1]

[0]: https://lists.sr.ht/~technomancy/fennel/patches/27973
[1]: xordspar0@gmail.com

✓ #664020 SUCCESS fennel/patches/.build.yml https://builds.sr.ht/~technomancy/job/664020
Details
Message ID
<87zgoap3b1.fsf@mntre-builder>
In-Reply-To
<20220105050724.174804-1-xordspar0@gmail.com> (view parent)
DKIM signature
permerror
Download raw message
Thanks!

The nested match makes me think it could be a good use case for the
nested error handling variant of match we've been talking about.

I've applied and pushed.

-Phil
Details
Message ID
<3VY85R.CYX1HGUWE66N1@gmail.com>
In-Reply-To
<87zgoap3b1.fsf@mntre-builder> (view parent)
DKIM signature
pass
Download raw message
On Wed, Jan 5, 2022 at 8:14 am, Phil Hagelberg <phil@hagelb.org> wrote:

> The nested match makes me think it could be a good use case for the
> nested error handling variant of match we've been talking about.

Yes, I noticed that too!

> I've applied and pushed.

Thanks!
Reply to thread Export thread (mbox)