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

Wrap all/1 returns with an ok-tuple #27

Open
joeljuca opened this issue Sep 9, 2024 · 1 comment
Open

Wrap all/1 returns with an ok-tuple #27

joeljuca opened this issue Sep 9, 2024 · 1 comment

Comments

@joeljuca
Copy link
Owner

joeljuca commented Sep 9, 2024

SwissSchema's all/1 should be returning lists wrapped in ok-tuples:

# Today, all/1 returns a raw list:
User.all() # => [%User{}, %User{}, %User{}, ...]

# It should, instead:
User.all() # => {:ok, [%User{}, %User{}, %User{}, ...]}

The reason is simple: it's an IO op, which might fail due to reasons (network failure, db perms, schema mismatch, etc.). I know it differs from Ecto's default behavior, but I think we might improve the DX by standardizing the returned structure of this function.

Also, if Ecto's all/2 throws errors when things go wrong, we should be rescuing them to returning error-tupled values:

# Something is wrong – eg.: network is unavailable
User.all() # => {:error, %SomeError{}}
@joeljuca
Copy link
Owner Author

joeljuca commented Sep 9, 2024

And now I'm wondering: should we have an equivalent bang function all!/1? 🤔

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

No branches or pull requests

1 participant