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

Type mismatch error #226

Open
smalloff opened this issue Aug 10, 2023 · 1 comment
Open

Type mismatch error #226

smalloff opened this issue Aug 10, 2023 · 1 comment

Comments

@smalloff
Copy link

smalloff commented Aug 10, 2023

I have problems with the handler. When I try to call some functions in the body of the handler, I get an error. How to deal with it?

My code:

`import prologue
import fastcmspkg/utils
import prologue/core/uid
import tinypool/sqlitePool
import db_connector/db_sqlite
import tinypool/core
import fastcmspkg/templates/nwt

var templates: Nwt

proc hello*(ctx: Context) {.async.} =
var
s: string

s = templates.renderTemplate("main.html", %*{"faa": "super"}) # If removed, the problem will disappear.
resp "Main page from plugin!" & genUid() & ctx.request.hostName() & s

proc Init(app: Prologue, db_pool: ConnectionPool[DbConn], templ: Nwt){.exportPlugin.} =
SQLITE_POOL = db_pool
templates = templ
echo "init plugin " & instantiationInfo().filename
app.get("/", hello) # this error!`

My console log:

d:\nim-2.0.0\projects\fastcms\src\plugins\main page\main_page.nim(32, 6) Error: type mismatch
Expression: get(app, "/", hello)
[1] app: Prologue
[2] "/": string
[3] hello: proc (ctx: Context): Future[system.void]

Expected one of (first mismatch at [position]):
[1] func get(env: Env; key: string): string
[1] proc get(group: Group; route: string; handler: HandlerAsync; name = "";
middlewares: openArray[HandlerAsync] = @[])
[1] proc get[T](self: Option[T]): lent T
[1] proc get[T](self: Option[T]; otherwise: T): T
[1] proc get[T](self: var Option[T]): var T
[3] proc get(app: Prologue; route: string; handler: HandlerAsync; name = "";
middlewares: openArray[HandlerAsync] = @[])

@mrtlsc
Copy link

mrtlsc commented Mar 4, 2024

I had the same problem. Proc hello has to be of type HandlerAsync, which is proc(ctx: Context): Future[void] {.closure, gcsafe.}. hello is not GC-safe, because it accesses a global variable templates. At least that's what the compiler should say if you add .gcsafe pragma to the proc.

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

No branches or pull requests

2 participants