avram
avram copied to clipboard
Save error doesn't give user a clue
https://github.com/luckyframework/avram/blob/02496a12c817e2fdfcf6d55834e1380afabe6e2d/src/avram/save_operation.cr#L324
This renders as:
Unhandled exception: Could not perform RegisterUser.
▸ save_user_options: failed
(Avram::InvalidOperationError)
from lib/avram/src/avram/save_operation.cr:322:7 in 'save!'
from lib/shield/src/presets/user.cr:23:1 in 'create!'
from tasks/db/seed/required_data.cr:35:5 in 'call'
The problem was a missing field after a migration. So, Postgres probably had something to say. But no clue was passed to the user.
Looks like in this specific situation the failure is coming from a nested save operation.
Thinking about this error, the best improvement I can think of would be to keep this basic error structure (wording) but then get the error from the nested operation and set it as the cause of this error. That way we get the context of this operation failed for this reason and that happened because of this other reason.
The hurdle to overcome with this is that errors are currently stored without a reference to the connected attribute https://github.com/luckyframework/avram/blob/02496a12c817e2fdfcf6d55834e1380afabe6e2d/src/avram/operation_errors.cr#L1
Errors don't have to be connected to a specific attribute so if that reference is added, we will need to make sure it is entirely optional.
This was partially discussed here https://github.com/luckyframework/avram/pull/596#discussion_r562928035. Nested save operations has some edge cases to work on.
Maybe an issue should be created specifically for this (if it does not already exists).