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

Breaking changes between Giraffe 0.1.0-alpha-025 and 0.1.0-beta001 #80

Closed
ryukinix opened this issue Aug 13, 2017 · 4 comments
Closed

Comments

@ryukinix
Copy link

I don't know if this was intended, but based on the template of few days ago when I try compile my project with the new version, I got:

"/home/lerax/Desktop/dchart/src/Backend/Backend.fsproj" (default target) (1) ->
(CoreCompile target) -> 
  /home/lerax/Desktop/dchart/src/Backend/Server.fs(40,13): error FS0001: Type mismatch. Expecting a�    'HttpContext -> 'a'    �but given a�    'HttpFunc -> 'b -> HttpFuncResult'    �The type 'HttpContext' does not match the type 'HttpFunc' [/home/lerax/Desktop/dchart/src/Backend/Backend.fsproj]
  /home/lerax/Desktop/dchart/src/Backend/Server.fs(40,13): error FS0001: Type mismatch. Expecting a�    'HttpContext -> 'a'    �but given a�    'HttpFunc -> 'b -> HttpFuncResult'    �The type 'HttpContext' does not match the type 'HttpFunc' [/home/lerax/Desktop/dchart/src/Backend/Backend.fsproj]
  /home/lerax/Desktop/dchart/src/Backend/Server.fs(47,32): error FS0001: The type 'HttpFunc' is not compatible with the type 'HttpContext' [/home/lerax/Desktop/dchart/src/Backend/Backend.fsproj]

Running through 0.1.0-alpha-025 I got compiling fine, I just want know what is design changes on the new beta.

Where the source is basically the template default:
image

ryukinix added a commit to ryukinix/dchart that referenced this issue Aug 13, 2017
This should be done because Giraffe has break changes on the new
beta001 version. Which can be explained here:

giraffe-fsharp/Giraffe#80
@gerardtoconnor
Copy link
Member

The error handler needs to be updated to use new HttpHandler format such that it additionally accepts a 'HttpFunc' functions as well as 'HttpContext' like 'fun next ctx ->. ..'

In the last line where handlers are composed, instead of 'ctx |> (handler)' you need to apply both parameters to functions like '(handler) next ctx'

@ryukinix
Copy link
Author

ryukinix commented Aug 13, 2017

Yes, I understand. Your tip fixed the problem. I can know why this change was made? Is related to the new Task support #53?

If anyone struggle with it too, the new errorHandler which works is it:

// ---------------------------------
// Error handler
// ---------------------------------

let errorHandler (ex : Exception) (logger : ILogger) (next: HttpFunc) (ctx : HttpContext) =
    logger.LogError(EventId(0), ex, "An unhandled exception has occurred while executing the request.")
    (clearResponse >=> setStatusCode 500 >=> text ex.Message) next ctx

@gerardtoconnor
Copy link
Member

gerardtoconnor commented Aug 13, 2017

Both this continuation update and task were done for performance reasons, you can read blog post I did to explain performance benefits here if your interested.

https://medium.com/@gerardtoconnor/carry-on-continuation-over-binding-pipelines-for-functional-web-58bd7e6ea009

It's a slightly more complex way of doing the handlers but there is a focus on performance and the consensus was it was worth breaking now for the long run.

If you have anymore issues let me know, happy to help.

@dustinmoris
Copy link
Member

dustinmoris commented Aug 13, 2017

Apologies for this issue. Even though I have updated the latest giraffe-template, the previous versions break now when you pull the beta package from an alpha template. I should have not referenced giraffe with a wildcard in the .fsproj. I will set it to a specific version going forward with the new template releases, but meanwhile if someone runs into this issue you can either pin the latest giraffe alpha package, or preferably update the error handler to match the new beta. You can simplify the error handler even further:

let errorHandler (ex : Exception) (logger : ILogger) =
    logger.LogError(EventId(), ex, "An unhandled exception has occurred while executing the request.")
    clearResponse >=> setStatusCode 500 >=> text ex.Message

Also please update the giraffe-template by running:

dotnet new -i giraffe-template::0.1.7

dustinmoris added a commit that referenced this issue Aug 13, 2017
…sion 0.1.8 will always continue to work. Fixes #80 for the future.
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

3 participants