Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware not found in registry even when it's there #216

Closed
msolli opened this issue Feb 4, 2019 · 2 comments
Closed

Middleware not found in registry even when it's there #216

msolli opened this issue Feb 4, 2019 · 2 comments
Labels

Comments

@msolli
Copy link

msolli commented Feb 4, 2019

I've created a minimal example to demonstrate this problem:
https://github.com/msolli/reitit-missing-middleware

I’m setting up coercion, but I’m running into an exception. According to the docs:

The coercion middleware are compiled againts a route. In the middleware compilation step the actual coercer implementations are constructed for the defined models. Also, the middleware doesn't mount itself if a route doesn't have :coercion and :parameters or :responses defined.

So I should be able to declare routes like this:

  [
   [""
    {:middleware [:app.middleware/coerce-request
                  :app.middleware/coerce-response
                  :app.middleware/coerce-exceptions
                  :app.middleware/defaults]}

    ["/" ::home-page]]
    ;; More routes here that actually have coercions...
  ])

I make sure to pass in a map for :reitit.middleware/registry that includes the referenced middlewares.

Still, when the routes are created and compiled, I get an exception claiming the middleware is not in the registry:

clojure.lang.ExceptionInfo: Middleware :app.middleware/coerce-request not found in registry.

Available middleware in registry:

|                                  :id |                                                                                                                                                                         :description |
|--------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|    :app.middleware/coerce-request | {:name :reitit.ring.coercion/coerce-request, :spec :reitit.spec/parameters, :compile #object[reitit.ring.coercion$fn__172563 0x194605f7 "reitit.ring.coercion$fn__172563@194605f7"]} |
|   :app.middleware/coerce-response |   {:name :reitit.ring.coercion/coerce-response, :spec :reitit.spec/responses, :compile #object[reitit.ring.coercion$fn__56703 0x36e4e57e "reitit.ring.coercion$fn__56703@36e4e57e"]} |
| :app.middleware/coerce-exceptions |                               {:name :reitit.ring.coercion/coerce-exceptions, :compile #object[reitit.ring.coercion$fn__56716 0x7a95f7d4 "reitit.ring.coercion$fn__56716@7a95f7d4"]} |
|          :app.middleware/defaults |                                               {:name :app.middleware/wrap-defaults, :wrap #object[app.middleware$fn__212347 0x6b916d5 "app.middleware$fn__212347@6b916d5"]} |

It fails when compiling the ::home-page route, which does not have any coercion. Hence the coerce-request compile function returns nil, which causes into-middleware to throw.

@ikitommi
Copy link
Member

Finally had time to look for this. So, this happens:

  1. the mw is looked from the registry
  2. it is found and coerced into a Middleware, e.g. running it's :compile
  3. the compile returns nil for the other route (the coercion only mounts if there is both :coercion and :parameters defined, see here

Fixed in master.

@ikitommi ikitommi added the bug label Feb 19, 2019
@ikitommi
Copy link
Member

fix released as part of [metosin/reitit "0.3.0-SNAPSHOT"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants