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

Bug report for trillium-api: wanting a State and not getting it should *usually* be a 500, not a 404 #688

Open
joshtriplett opened this issue Jan 25, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@joshtriplett
Copy link
Collaborator

joshtriplett commented Jan 25, 2025

Multiple times, I've run into the bug that the state map didn't have the type I was expecting in it. trillium-api treats an unavailable State<T> parameter as a failure to use that route, and thus a 404. However, based on experience with trillium-api, it seems like a missing State<T> is often an internal server error.

When a non-optional State<T> parameter fails to be available, I think it would make sense to:

  1. Produce a 500 Internal Server Error.
  2. Produce an error message to the log.
@joshtriplett joshtriplett added the bug Something isn't working label Jan 25, 2025
@jbr
Copy link
Contributor

jbr commented Feb 3, 2025

I don't think this is a bug, in that it behaves as I expect and intend. I tend to treat "state not populated" to mean something like "we couldn't find the record," which is a 404. However, your expectation of "state not populated" meaning "our application is broken because the type in state is a critical component that should always be populated" also seems valid and reasonable. Can you describe the situation in which something should have been populated into State but was not? It seems like the place that populates the State is where I'd expect to halt and log and populate an error of some sort, but I can't be sure of that without more context

@joshtriplett
Copy link
Collaborator Author

The scenario I've most often observed: calling a function that returns an Option<T> or Result<T, E> and accidentally putting that into the state map without first extracting the T from it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants