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

Proposal: Operations should assertState #355

Open
josephjclark opened this issue Aug 18, 2023 · 0 comments
Open

Proposal: Operations should assertState #355

josephjclark opened this issue Aug 18, 2023 · 0 comments

Comments

@josephjclark
Copy link
Collaborator

This is proposal for a new pattern to help developers.

Some adaptors rely on stuff being in state - for example, database-facing adaptors often have some kind of client.

A common bug is for a job to return { data } from an operation - which seems harmless but will accidentally break the job code when an adaptor tries to do state.client.doSomething.

I rebelled against this pattern a little while ago and proposed using a closure rather than state to track clients. I may have forgotten about that stuff. It's still a pattern to consider.

Anyway - for operations that DO rely on state, we should provide a common util function called assertState(state, ...keys)

This function throws if any of the keys are not found on the state object. We can throw a message like Error: 'client' not found on state object. Did you remember to return state from the previous job?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Icebox
Development

No branches or pull requests

1 participant