SaturnFramework / Saturn

Opinionated, web development framework for F# which implements the server-side, functional MVC pattern
https://saturnframework.org
MIT License
705 stars 108 forks source link

PrintfFormat routes cause exception on startup #272

Open dsshep opened 3 years ago

dsshep commented 3 years ago

Using the template here.

Changing the Router.fs to something like:

let getNameAndAge nameAndAge next ctx = 
    let name, age = nameAndAge
    Successful.OK (json name) next ctx

let defaultView = router {
    get "/" (htmlView Index.layout)
    get "/index.html" (redirectTo false "/")
    get "/default.html" (redirectTo false "/")
    getf "/%s/%i" getNameAndAge
}

Causes an exception on startup: Exception thrown: 'System.NullReferenceException' in Unknown Module. Object reference not set to an instance of an object.

It doesn't seem to happen with a single format specifier, e.g. getf "/%s" getName would be fine.

Although once the application has started the route will work. In VS on windows, this will be caught in the break mode window. On Mac (and probably Linux) this will cause dotnet to crash along with the debug session:

image
SreeAtRA commented 3 years ago

I am running into a similar problem during router initialization. The image shows the call stack from Visual Studio.

image

Krzysztof-Cieslak commented 3 years ago

This is probably caused by the fact that the first formater is %s and it eagerly matches the whole route, so then it can't match the second formatter.