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

Remove try/catch for short url so the appropriate errors will be propagated to the UI #13004

Merged
merged 15 commits into from
Jul 28, 2017

Conversation

stacey-gammon
Copy link
Contributor

@stacey-gammon stacey-gammon commented Jul 20, 2017

Previously, any error with a short url, e.g. looking for one that didn't exist, or encountering an auth exception, would all result in the same ambiguous error:

{"statusCode":406,"error":"Not Acceptable","message":"Short url target path must be in the format \"/app/{{appId}}\", found \"/\""}

With this change, the right "not found" Boom error will be sent to the user, as should auth exceptions (that was hard to test since you can't log in to kibana without read permissions, but theoretically it should be propagated as well).

Fixes #10456

cc @spalger - you commented on the original issue so tagging you if you want to take a look.

@spalger
Copy link
Contributor

spalger commented Jul 20, 2017

I'm concerned with the potential BWC impact of a change like this.

Also, since this is going to lead to more error responses I took a look at src/server/http/short_url_error.js, which I think needs to be updated to just wrap the error object rather than replace it with new Boom errors. At least the function is checking if the error is a Boom error first, but replacing the entire function with Boom.wrap(error, error.status || 500); would do the same thing without discarding the original error.

PS: unlike the name suggests, Boom.wrap() preserves the original error but decorates it with the necessary properties to behave like a Boom error

@stacey-gammon
Copy link
Contributor Author

Can you explain a bit more about the BWC concerns? As far as I can tell, any error previously would have showed up with the '/' error, but now the error will be different. You think people will be relying on the '/' error? I def don't want to cause any harm, but it does seem weird that errors are swallowed and replaced with a different, random error.

If this gets in to 6.0, we don't have to be as concerned with BWC... ?

@spalger
Copy link
Contributor

spalger commented Jul 20, 2017

Yeah, that's the only thing I was concerned with. That said, I think as long as what was once an error is still an error I'm good with it. And yeah, if we get this into 6.0 then there really aren't any BWC concerns.

@stacey-gammon
Copy link
Contributor Author

Failing on:

  single test that uses esArchiver
     │ debg  Loading config file from "/var/lib/jenkins/workspace/elastic+kibana+pull-request+multijob-intake/src/functional_test_runner/__tests__/fixtures/with_es_archiver/config.js"
     │ info  starting elasticsearch
       │ debg  WARN: bootstrap_checks - max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
       │ debg  WARN: unicast_zen_ping - [1] failed send ping to {#zen_unicast_127.0.0.1_0#}{tbmLBf5RSxerQY61HCAOTA}{127.0.0.1}{127.0.0.1:9300}
       │ debg  WARN: unicast_zen_ping - [1] failed send ping to {#zen_unicast_127.0.0.1_0#}{tbmLBf5RSxerQY61HCAOTA}{127.0.0.1}{127.0.0.1:9300}
       │ debg  WARN: unicast_zen_ping - [1] failed send ping to {#zen_unicast_127.0.0.1_0#}{tbmLBf5RSxerQY61HCAOTA}{127.0.0.1}{127.0.0.1:9300}
     │ info  starting kibana
{"type":"log","@timestamp":"2017-07-21T12:37:39Z","tags":["listening","info"],"pid":10383,"message":"Server running at http://localhost:5701"}
     │ debg   info  Config loaded
     │        info  Starting tests
     │       
     │        └-: tests
     │          └-> "before all" hook
     │            │ info  [test_archive] Loading "mappings.json"
     │          └- ✖ fail: "tests "before all" hook"
     │          │        [illegal_argument_exception] unknown setting [index.mapping.single_type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
     │          │         :: {"path":"/.kibana","query":{},"body":"{\"settings\":{\"index\":{\"mapping\":{\"single_type\":\"false\"},\"number_of_shards\":\"1\",\"mapper\":{\"dynamic\":\"fal

Will merge again with master and push

@spalger
Copy link
Contributor

spalger commented Jul 21, 2017

Sorry @stacey-gammon, fixed that in #13021

@spalger
Copy link
Contributor

spalger commented Jul 21, 2017

jenkins, test this

@stacey-gammon
Copy link
Contributor Author

Hmm, thought I merged with the latest to grab the fix. Failing on:

  single test that uses esArchiver
     │ debg  Loading config file from "/var/lib/jenkins/workspace/elastic+kibana+pull-request+multijob-intake/src/functional_test_runner/__tests__/fixtures/with_es_archiver/config.js"
     │ info  starting elasticsearch
       │ debg  WARN: bootstrap_checks - max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
       │ debg  WARN: unicast_zen_ping - [1] failed send ping to {#zen_unicast_127.0.0.1_0#}{OGSHWNcqR0GPXdMRvM6gig}{127.0.0.1}{127.0.0.1:9300}
       │ debg  WARN: unicast_zen_ping - [1] failed send ping to {#zen_unicast_127.0.0.1_0#}{OGSHWNcqR0GPXdMRvM6gig}{127.0.0.1}{127.0.0.1:9300}
       │ debg  WARN: unicast_zen_ping - [1] failed send ping to {#zen_unicast_127.0.0.1_0#}{OGSHWNcqR0GPXdMRvM6gig}{127.0.0.1}{127.0.0.1:9300}
     │ info  starting kibana
{"type":"log","@timestamp":"2017-07-21T19:27:01Z","tags":["listening","info"],"pid":11150,"message":"Server running at http://localhost:5701"}
     │ debg   info  Config loaded
     │        info  Starting tests
     │       
     │        └-: tests
     │          └-> "before all" hook
     │            │ info  [test_archive] Loading "mappings.json"
     │          └- ✖ fail: "tests "before all" hook"
     │          │        [illegal_argument_exception] Rejecting mapping update to [.kibana] as the final mapping would have more than 1 type: [server, index-pattern, visualization, search, timelion-sheet, config, url, dashboard]
     │          │         :: {"path":"/.kibana","query":{},"body":"{\"settings\":{\"index\":{\"number_of_shards\":\"1\",\"mapper\"

@stacey-gammon
Copy link
Contributor Author

Confirmed i'm on the latest version.

jenkins, test this

@stacey-gammon
Copy link
Contributor Author

tests now passing, ready for a final look.

if (err.status === 404) return Boom.notFound();
return Boom.badImplementation();
export function handleShortUrlError(error) {
if (!error.isBoom && !(error instanceof Error)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We really should not support non-errors here. Pretty sure this was spurred by the tests failing because they aren't sending real errors, which means that this code isn't actually testing what would happen in production with this condition. I think this check should go, we should always use Boom.wrap() and the tests should use real error objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do that, I was just worried about changing implementation details, not knowing if I would create a subtle bug somewhere.

@stacey-gammon
Copy link
Contributor Author

jenkins, test this

@tylersmalley
Copy link
Contributor

jenkins, test it

@stacey-gammon
Copy link
Contributor Author

Failed on:

281      └-: data-shared-item
01:48:58.281        └-> should have correct data-shared-item title and description
01:48:58.281          └-> "before each" hook: global before each
01:48:58.288            │ debg  Kibana uiSettings are in elasticsearch and the server is reporting a green status
01:48:58.288          │ debg  TestSubjects.find(discoverOpenButton)
01:48:58.290          │ debg  in displayedByCssSelector: [data-test-subj~="discoverOpenButton"]
01:48:58.421          │ debg  TestSubjects.find(globalLoadingIndicator)
01:48:58.421          │ debg  in displayedByCssSelector: [data-test-subj~="globalLoadingIndicator"]
01:48:58.607          │ debg  Taking screenshot "/var/lib/jenkins/workspace/elastic+kibana+pull-request+multijob-selenium/test/functional/screenshots/failure/discover app discover app data-shared-item should have correct data-shared-item title and description.png"
01:48:58.866        └- ✖ fail: "discover app discover app data-shared-item should have correct data-shared-item title and description"
01:48:58.867        │       
01:48:58.867        │         Error: expected 'Query # 1' to sort of equal 'A Saved Search'
01:48:58.867        │         + expected - actual
01:48:58.867        │       
01:48:58.867        │         -Query # 1
01:48:58.867        │         +A Saved Search
01:48:58.867        │         
01:48:58.867        │         at Assertion.assert (node_mo

Looks like a flaky test. Will sync with master and try again.

it(`should handle ${err.status} errors`, function () {
expect(_.get(handleShortUrlError(err), 'output.statusCode')).to.be(err.status);
it(`should handle ${err.status || err.statusCode} errors`, function () {
expect(_.get(handleShortUrlError(err), 'output.statusCode')).to.be(err.status || err.statusCode);
Copy link
Contributor

@spalger spalger Jul 27, 2017

Choose a reason for hiding this comment

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

The first error in uncaughtErrors is going to have a status and statusCode of undefined, right? Isn't that I think these three tests should just be written separately, rather than implementing unnecessary looping/conditional checking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

++

I split out the status and statusCode checks, but the errors in those two test loops should always have either status or statusCode defined. Only uncaughtErrors test has a case when they are both undefined.

@stacey-gammon stacey-gammon merged commit 3f54e94 into elastic:master Jul 28, 2017
stacey-gammon added a commit to stacey-gammon/kibana that referenced this pull request Jul 28, 2017
…agated to the UI (elastic#13004)

* Remove try/catch for short url so the appropriate errors will be propagated to the UI

* Simply ensure the error is a Boom error by wrapping it, but keep the original error details.

* Boom.wrap can't handle non Error instances, as exist in some of the tests.

* Only support Error objects, and check both status and statusCode

* fix test

* Fix test errors for reals this time

* Break out status and statusCode short url error tests
stacey-gammon added a commit that referenced this pull request Jul 28, 2017
…agated to the UI (#13004) (#13179)

* Remove try/catch for short url so the appropriate errors will be propagated to the UI

* Simply ensure the error is a Boom error by wrapping it, but keep the original error details.

* Boom.wrap can't handle non Error instances, as exist in some of the tests.

* Only support Error objects, and check both status and statusCode

* fix test

* Fix test errors for reals this time

* Break out status and statusCode short url error tests
@stacey-gammon stacey-gammon deleted the fix/show-short-url-errors branch October 24, 2017 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants