servant-auth icon indicating copy to clipboard operation
servant-auth copied to clipboard

Add an error parameter to the ThrowAll typeclass

Open AJChapman opened this issue 6 years ago • 6 comments

This is so that an application can use its own custom error type and still call throwAll.

AJChapman avatar Jul 22 '19 06:07 AJChapman

Could you define type ThrowAll = ThrowAll' ServerError to avoid a major breaking change?

domenkozar avatar Jul 22 '19 07:07 domenkozar

@domenkozar I have tried your suggestion but I can't get it to work. For example, with the type alias we still get errors like this:

src/Servant/Auth/Server.hs:128:5-22: error:
    • The type constructor ‘ThrowAll’ is not the parent of the identifier ‘throwAll’.
      Identifiers can only be exported with their parent type constructor.
      Parent: ThrowAll'
    • In the export: ThrowAll(throwAll)
    |
128 |   , ThrowAll(throwAll)
    |     ^^^^^^^^^^^^^^^^^^

I think to avoid a breaking change I would have to create typeclass ThrowAll', with function throwAll', and leave the existing ThrowAll typeclass, function throwAll, and instances all in place. Should I do it that way?

AJChapman avatar Aug 05 '19 02:08 AJChapman

Maybe that's a good candidate for servant then: https://github.com/haskell-servant/servant/issues/765

@phadej @alpmestan what do you think?

domenkozar avatar Aug 05 '19 11:08 domenkozar

I wonder if that's what https://hackage.haskell.org/package/servant-generate-0.1/docs/Servant-Server-Generate.html does.

phadej avatar Aug 12 '19 22:08 phadej

servant-generate was inspired by -auth's venerable ThrowAll :-)

And I think it should cover this use case, indeed.

alpmestan avatar Aug 14 '19 20:08 alpmestan

See #168

domenkozar avatar Aug 25 '20 13:08 domenkozar