-
Notifications
You must be signed in to change notification settings - Fork 33
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
1380 function clause error changeset json error #1393
1380 function clause error changeset json error #1393
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1393 +/- ##
==========================================
- Coverage 85.82% 85.81% -0.02%
==========================================
Files 216 216
Lines 6393 6393
==========================================
- Hits 5487 5486 -1
- Misses 906 907 +1 ☔ View full report in Codecov by Sentry. |
lib/lightning/attempts/handlers.ex
Outdated
case get_run(complete_run.run_id) do | ||
nil -> | ||
# Return an error changeset when the run is not found | ||
%Run{} | ||
|> change() | ||
|> put_change(:exit_reason, "error") | ||
|> put_change(:error_type, "Run not found") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is the way to go about it. In the case of an error we don't return a Run changeset, we return a CompleteRun
changeset, it's purpose is to stand in between the worker sending a bunch of data that represents data that is for a run and a dataclip. It can be thought of as a 'command'.
My suggestion is to add a run: Run
field to the schema, we don't cast it - but set the field and then validate it.
# ... ^ new/1
|> then(&assign_run/1)
end
defp assign_run(changeset) do
with %{valid?: true} <- changeset,
%Run{} = run <-
get_field(changeset, :run_id) |> get_run() || :not_found do
put_change(changeset, :run, run)
else
:not_found ->
add_error(changeset, :run_id, "not found")
changeset ->
changeset
end
end
And then further down the update/1
function can assume the changeset is valid, and get the run
off the changeset instead of finding it itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposal is to be very granular with the fix changing only the flow of the complete run.
The change consists of just adding the changeset to the returned value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to keep the previous order of validations and I think this change as 9ef9359 is safer, going directly to the point by adding the validation only to the flow reported on the error (on new/insertion
the validation won't be needed)
lib/lightning/attempts/handlers.ex
Outdated
with {:ok, _} <- to_dataclip(complete_run) |> Repo.insert(), | ||
%Run{} = run <- get_run(complete_run.run_id) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry Ben, just noticed after the pairing that the get_run
makes more sense before the dataclip insertion as it was previously.
lib/lightning/attempts/handlers.ex
Outdated
nil -> | ||
{:error, | ||
%Run{} | ||
|> change() | ||
|> add_error(:run_id, "not found")} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't return a Run changeset. As mentioned in my first review:
In the case of an error we don't return a Run changeset, we return a CompleteRun changeset
The Run model does not have a :run_id
key. You have access to the original CompleteRun
changeset. Please change the nil
case to:
{:error, complete_run |> add_error(:run_id, "not found")}
Notes for the reviewer
Update the CompleteRun handler in Lightning.Attempts.Handlers to handle
cases where a run is not found by returning a detailed error changeset.
Related issue
Fixes #1380
Review checklist