Skip to content

Fix extracting Sentry external URL when URL is nil

Peter Leitzen requested to merge pl-nil-guard-extract-sentry-external-url into master

What does this MR do?

This MR fixes a ~bug where an inactive error tracking setting had no api_url and was saved successfully.

Extracting the Sentry's external URL via settings.sentry_external_url would fail in this case. This came up during testing of the Sentry API endpoint.

Note that there's no issue for this MR hence Stuff that should Just Work label (refs Incremental improvements).

Reproduction

This error is easy to reproduce:

  1. Go to Operation Settings > Error Tracking
  2. Leave form empty (do not activate)
  3. Click Save
  4. Fetch error tracking via API: See !21788 (diffs)
  5. 💥

The exception:

NoMethodError (undefined method `sub' for nil:NilClass
Did you mean?  stub):
  /home/peter/devel/gitlab/gdk-ee/gitlab/app/models/error_tracking/project_error_tracking_setting.rb:131:in `extract_sentry_external_url'
  /home/peter/devel/gitlab/gdk-ee/gitlab/app/models/error_tracking/project_error_tracking_setting.rb:80:in `sentry_external_url'
  /home/peter/.dotfiles/asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/grape-entity-0.7.1/lib/grape_entity/delegator/plain_object.rb:8:in `delegate'
  /home/peter/.dotfiles/asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/grape-entity-0.7.1/lib/grape_entity/entity.rb:512:in `delegate_attribute'
  /home/peter/.dotfiles/asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/grape-entity-0.7.1/lib/grape_entity/exposure/delegator_exposure.rb:8:in `value'
  /home/peter/.dotfiles/asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/grape-entity-0.7.1/lib/grape_entity/exposure/base.rb:82:in `valid_value'

... more grape stacktace

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Peter Leitzen

Merge request reports