surface errors to ui when script update fails #38742
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
background
This PR addresses the following issue:
EXPECTED: fails with error explaining that migrated scripts cannot be marked visible (yet)
ACTUAL: fails silently with success message
root cause
this validation was failing:
code-dot-org/dashboard/app/models/script.rb
Lines 123 to 125 in 8845df6
an ActiveRecord::RecordInvalid error was being raised:
code-dot-org/dashboard/app/models/script.rb
Line 1154 in 8845df6
the error was being caught and added to the list of errors on the script object:
code-dot-org/dashboard/app/models/script.rb
Lines 1183 to 1184 in 8845df6
the errors were even being returned to the client:
code-dot-org/dashboard/app/controllers/scripts_controller.rb
Line 132 in 36bf378
but, because the status code was not a 4xx, the client treated the response as a success.
fix
The fix is just to set the right status code in the server response. The client code then takes care of displaying the error message.
before
after
Future work
in the process of debugging this, I discovered that there are nested transactions in this codepath:
code-dot-org/dashboard/app/models/script.rb
Lines 1163 to 1168 in def7f2c
code-dot-org/dashboard/app/models/script.rb
Lines 989 to 990 in def7f2c
and that with default options, nested transactions are bad:
Fixed in #38775
Testing story
existing test coverage, plus manually verifying the result shown in the screenshots above.
Reviewer Checklist: