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

surface errors to ui when script update fails #38742

Merged
merged 1 commit into from Jan 28, 2021

Conversation

davidsbailey
Copy link
Member

@davidsbailey davidsbailey commented Jan 27, 2021

background

This PR addresses the following issue:

  1. go to https://levelbuilder-studio.code.org/s/csp1-2021/edit
  2. under "Publishing Settings", select "Visible in Teacher Dashboard"
  3. press "Save and Keep Editing"

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:

def set_is_migrated_only_for_migrated_scripts
if !!is_migrated && !hidden
errors.add(:is_migrated, "Can't be set on a course that is visible")

an ActiveRecord::RecordInvalid error was being raised:

script.update!(options.merge(skip_name_format_validation: true))

the error was being caught and added to the list of errors on the script object:

rescue StandardError => e
errors.add(:base, e.to_s)

the errors were even being returned to the client:

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

Screen Shot 2021-01-26 at 4 21 23 PM

after

Screen Shot 2021-01-26 at 4 06 19 PM

Future work

in the process of debugging this, I discovered that there are nested transactions in this codepath:

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:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@davidsbailey davidsbailey marked this pull request as ready for review January 28, 2021 12:27
Copy link
Contributor

@dmcavoy dmcavoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for finding this!

@davidsbailey davidsbailey merged commit 1f7f3ce into staging Jan 28, 2021
@davidsbailey davidsbailey deleted the report-script-update-error branch January 28, 2021 22:59
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

Successfully merging this pull request may close these issues.

None yet

2 participants