OpenFn / OpenFn/adaptors

Proposal: Operations should assertState

Open
#355 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
24
Forks
41
Avg merge
3d 13h
Merged PRs (30d)
12

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing adaptor operations that rely on state, especially database-facing operations and the pattern of returning state between jobs. Done means a shared assertState(state, ...keys) utility is defined with the proposed missing-key error behavior and supports checking each requested key.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.