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

common: add assert() function #876

Closed
josephjclark opened this issue Jan 7, 2025 · 1 comment · Fixed by #898
Closed

common: add assert() function #876

josephjclark opened this issue Jan 7, 2025 · 1 comment · Fixed by #898

Comments

@josephjclark
Copy link
Collaborator

josephjclark commented Jan 7, 2025

Assert should take some expression or function and throw an error if either resolves to false.

This allows us to abort execution in the event of a fail state. It's a good replacement for eg salesforce's failOnError, and can be applied equally to all jobs and adaptors. It doesn't need special API support. Although the operation in question does need to provide enough feedback to make a useful assertion on - ie, it must write something useful to state.data.

It should take a second argument as an error message which will be returned.

Eg

assert($.data.errors === 0, "Errors detected in upsert")
assert($.data.length, "No patient data found!")
@github-project-automation github-project-automation bot moved this to New Issues in v2 Jan 7, 2025
@josephjclark
Copy link
Collaborator Author

This would replace failOnError in salesforce, which is a popular pattern.

One consideration is that assert is a bit less elegant when combined with each (although you can still do it!)

each($.data, bulk(...).then(assert($.res, 'some error')))

This will run the assertion after each bulk request and throw to abort the job as soon as one fails

@github-project-automation github-project-automation bot moved this from New Issues to Done in v2 Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant