Skip to content

refactor: simplify control flow in App.postgrest#4968

Merged
taimoorzaeem merged 1 commit into
PostgREST:mainfrom
mkleczek:push-txwxmomsyvsm
Jun 2, 2026
Merged

refactor: simplify control flow in App.postgrest#4968
taimoorzaeem merged 1 commit into
PostgREST:mainfrom
mkleczek:push-txwxmomsyvsm

Conversation

@mkleczek

@mkleczek mkleczek commented May 31, 2026

Copy link
Copy Markdown
Collaborator

Currently, authentication and response execution each unwrap ExceptT with separate runExceptT calls, which split the main request flow across nested pattern matching and Either handling. Control flow is complex and difficult to understand.

The goal of this change is to make request execution as sequential monadic code with clear error handling.

To implement that, request handling is now run in ExceptT over WriterT (Last ByteString) IO monad stack. Auth role is written after authentication succeeds and further returned along the response. Thanks to it response observation generation is centralized at the end of request handling.

It was necessary to abstract monad stack in getAuthResult, lookupJwtCache, postgrestResponse, and withTiming to enable introduction of WriterT.

@mkleczek mkleczek force-pushed the push-txwxmomsyvsm branch 5 times, most recently from 9d3be61 to e6b1371 Compare May 31, 2026 19:24
@mkleczek mkleczek force-pushed the push-txwxmomsyvsm branch 3 times, most recently from 78ff9fc to bd525bc Compare June 1, 2026 06:24
Comment thread src/PostgREST/App.hs Outdated

@taimoorzaeem taimoorzaeem left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mkleczek mkleczek force-pushed the push-txwxmomsyvsm branch from bd525bc to e206b59 Compare June 1, 2026 11:21
Comment thread src/PostgREST/App.hs Outdated
Currently, authentication and response execution each unwrap ExceptT with separate runExceptT calls, which split the main request flow across nested pattern matching and Either handling. Control flow is complex and difficult to understand.

The goal of this change is to make request execution as sequential
monadic code with clear error handling.

To implement that, request handling is now run in ExceptT over WriterT (Last ByteString) IO monad stack. Auth role is written after authentication succeeds and further returned along the response. Thanks to it response observation generation is centralized at the end of request handling.

It was necessary to abstract monad stack in getAuthResult, lookupJwtCache, postgrestResponse, and withTiming to enable introduction of WriterT.
@mkleczek mkleczek force-pushed the push-txwxmomsyvsm branch from e206b59 to d663421 Compare June 2, 2026 05:25
@taimoorzaeem taimoorzaeem merged commit 13c0e70 into PostgREST:main Jun 2, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants