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

BaseActiveRecord save method behaviour #20111

Open
zebraf1 opened this issue Feb 2, 2024 · 1 comment
Open

BaseActiveRecord save method behaviour #20111

zebraf1 opened this issue Feb 2, 2024 · 1 comment
Labels
status:ready for adoption Feel free to implement this issue. type:docs Documentation

Comments

@zebraf1
Copy link
Contributor

zebraf1 commented Feb 2, 2024

When calling save() on a model object, it hints that it returns true or false whether save succeeded. It does not hint any exceptions are thrown, however it calls insert() or update() which can throw db\Exception or Throwable.
So when the database configuration is wrong or database is not responsing then an Exception is thrown from save() and causes an unexpected error.

Either:
a) the exceptions should be caught within save(), logged and returns false
b) PHP doc for save() needs to be updated with [at]throws statement, so IDE's can detect it needs exception handling

@samdark samdark added the type:docs Documentation label Feb 9, 2024
@samdark
Copy link
Member

samdark commented Feb 9, 2024

Solution b) is preferred. Could you make a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready for adoption Feel free to implement this issue. type:docs Documentation
Projects
None yet
Development

No branches or pull requests

2 participants