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

Redirects can no longer be used in error blocks #269

Closed
reesmichael1 opened this issue Oct 24, 2020 · 2 comments · Fixed by #275
Closed

Redirects can no longer be used in error blocks #269

reesmichael1 opened this issue Oct 24, 2020 · 2 comments · Fixed by #275
Labels

Comments

@reesmichael1
Copy link

First, thanks for all your work on Jester! It's a very nice framework.

It seems that it's no longer possible to use a redirect within an error block with 0.5.0. With Jester 0.4.3, this snippet compiles and works as expected:

import jester

router root:
  get "/":
    resp "hello world"

  error Http404:
    redirect "404.html"

proc main() =
  var jester = initJester(root)
  jester.serve()

when isMainModule:
  main()

With 0.5.0, I get the following compilation error:

/home/reesmichael1/programs/scorecord/example.nim(4, 8) template/generic instantiation of `router` from here
/home/reesmichael1/.nimble/pkgs/jester-0.5.0/jester.nim(1331, 39) template/generic instantiation of `async` from here
/home/reesmichael1/programs/scorecord/example.nim(9, 14) template/generic instantiation of `redirect` from here
/home/reesmichael1/.nimble/pkgs/jester-0.5.0/jester.nim(592, 11) Error: undeclared identifier: 'allRoutes'

If I change the redirect to a resp, the sample successfully compiles.

I haven't dug into it enough to be certain, but it seems likely that this is due to the changes in #265. Adding halt = false to the redirect call makes no difference.

@dom96 dom96 added the Bug label Oct 24, 2020
@mildred
Copy link

mildred commented Nov 15, 2020

I have the same issue with my nimnews package. The code is rather simple:

proc root*(req: Request): Future[ResponseData] {.async.} =
  block route:
    redirect("/group/")

@pheynnx
Copy link

pheynnx commented Sep 13, 2021

I am having similar issues with Jester 0.5.0. When I use the macro routes: if I add the error block I can't use redirect

routes:
  get "/":
    redirect "/blog"
    
  error {Http401 .. Http408}:
    redirect "/somepathhere"

The redirect in the get: block will work just fine, but the redirect in the error: block will throw
Error: undeclared identifier: 'allRoutes'

Then if I move to a custom match proc like in exmaple2 I can't use redirect at all

proc match(request: Request): Future[ResponseData] {.async.} =
  block route:
    case request.pathInfo
    of "/":
      redirect "/blog"
    else:
      resp Http404, "Not found!"

The redirect in the of "/" will throw Error: undeclared identifier: 'allRoutes'

I am using:
nim v1.4.8
Windows WSL Ubuntu 20.04

iffy added a commit to iffy/jester that referenced this issue Jun 10, 2022
dom96 added a commit that referenced this issue Jun 13, 2022
* Fixes crash described in #296.

* Fix #211 - custom routers now get the same default error handling as normal routers

* Add changelog entry

* Fix #269 - you can now redirect within error handlers again

* Preserve backward compatibility in `initJester`

* Restore `initJester` proc for MatchProcSync matchers

Co-authored-by: Dominik Picheta <dominikpicheta@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants