Skip to content

Enhanced lat/long error handling#16833

Closed
jbertouch wants to merge 7 commits intoelastic:masterfrom
jbertouch:issue_16137
Closed

Enhanced lat/long error handling#16833
jbertouch wants to merge 7 commits intoelastic:masterfrom
jbertouch:issue_16137

Conversation

@jbertouch
Copy link
Copy Markdown
Contributor

Closes #16137.

Addresses issue elastic#16137. NumberFormatExceptions caused by non-double
lat/long values are now handled when the ignore_malformed flag is set
to true.
return point.resetFromGeoHash(geohash);
}
} else if (numberFormatException != null) {
throw new ElasticsearchParseException("[{}] and [{}] must be valid double values", LATITUDE, LONGITUDE);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This swallows the numberFormatException but it should instead be wrapped by the ElasticsearchParseException.

@jbertouch
Copy link
Copy Markdown
Contributor Author

Thanks @jasontedor, I hadn't familiarized myself with the ElasticsearchException hierarchy.

@jasontedor
Copy link
Copy Markdown
Member

@jbertouch Can you add tests in GeoPointFieldMapperTests#testValidateLatLonValues that test failing cases for the new code as well? The tests that are currently there do something that I do not like which is not validate that the contents of the exception are as expected, so let's not follow that pattern (but leave them how they are). Let me know if what I mean requires clarification.

@jasontedor jasontedor added review v5.0.0-alpha1 :Analytics/Geo Indexing, search aggregations of geo points and shapes labels Feb 28, 2016
@jbertouch
Copy link
Copy Markdown
Contributor Author

Hi @jasontedor, I added additional test failing cases to GeoPointFieldMapperTests#testValidateLatLonValues, which validate the wrapped exception type as a NumberFormatException, and I didn't alter the existing tests.

@jbertouch
Copy link
Copy Markdown
Contributor Author

FWIW, I ran a quick regex over the ES test packages - these are the tests with unvalidated/empty catch clauses for exceptions if you want to review them in future:

BulkRequestTests#testBulkAllowExplicitIndex
TransportReplicationActionTests#shardOperationOnReplica
JarHellTests#testInvalidVersions
AllocationCommandsTests#testAllocateCommand
AllocationCommandsTests#testCancelCommand
Base64Tests#assertInvalidBase64
IteratorsTests#testNull
IteratorsTests#testNullIterator
IteratorsTests#assertNoSuchElementException
HppcMapsTests#testIntersection
SimpleJodaTests#testThatRootObjectParsingIsStrict
SimpleJodaTests#assertDateFormatParsingThrowingException
CommonGramsTokenFilterFactoryTests#testDefault
KeepFilterFactoryTests#testLoadOverConfiguredSettings
KeepFilterFactoryTests#testKeepWordsPathSettings
ShadowEngineTests#testShadowEngineIgnoresWriteOperations
DynamicMappingTests#testTypeNotCreatedOnIndexFailure
GeoPointFieldMapperTests#testValidateLatLonValues
BoolQueryBuilderTests#testIllegalArguments
StoreTests#testCanReadOldCorruptionMarker
TypesExistsIT#testSimple
IndicesOptionsIntegrationIT#testAllMissingStrict
IndicesOptionsIntegrationIT#verify
CloseIndexDisableCloseAllIT#testCloseAllRequiresName
IndexStatsIT#testSimpleStats
DestructiveOperationsIntegrationIT#testDestructiveOperations
PercolatorIT#testSimple1
PercolatorIT#testPercolatingExistingDocs_versionCheck
PercolatorIT#testCountPercolation
SignificanceHeuristicTests#basicScoreProperties
SignificanceHeuristicTests#testScoreMutual
ChildQuerySearchIT#testParentFieldToNonExistingType
GeoFilterIT#testShapeBuilders
SearchScrollIT#testClearIllegalScrollId
SimpleSearchIT#testSearchNullIndex
SuggestSearchTests#testPhraseBoundaryCases
AbstractS3SnapshotRestoreTest#testRepositoryWithCustomCredentialsIsNotAccessibleByDefaultCredentials
AbstractS3SnapshotRestoreTest#testRepositoryInRemoteRegionIsRemote
BlockClusterStateProcessing#startDisrupting
IntermittentLongGCDisruption#BackgroundWorker#run
SlowClusterStateProcessing#BackgroundWorker#run

@jasontedor
Copy link
Copy Markdown
Member

This is looking good; can you add one more thing? In particular, assertions on the exception message?

@jbertouch
Copy link
Copy Markdown
Contributor Author

Hi Jason, I added/tested the extra assertions.

.bytes());
fail();
} catch (MapperParsingException e) {
assertTrue(e.getRootCause() instanceof NumberFormatException);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you use the dedicated instanceOf matcher instead of assertTrue? So, assertThat with instanceOf? The advantage of using the dedicated matchers is that it gives very nice error messages when the assertion fails (so with assertTrue all that we see when a test fails is something like "expected true but was false" and with the assertThat and a dedicated matcher something like "expected an instance of NumberFormatException but was IllegalArgumentException").

@jasontedor
Copy link
Copy Markdown
Member

Hi Jason, I added/tested the extra assertions.

@jbertouch Thanks, I left a comment that applies to all of the assertions. Getting close. :)

@jbertouch
Copy link
Copy Markdown
Contributor Author

@jasontedor Done!

@jasontedor
Copy link
Copy Markdown
Member

Done!

Great, thank you so much! I took a quick peek and it looks good. I'll take a final closer look later and wrap this up accordingly.

return point.resetFromGeoHash(geohash);
}
} else if (numberFormatException != null) {
throw new ElasticsearchParseException("[{}] and [{}] must be valid double values", numberFormatException, LATITUDE, LONGITUDE);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This line will break our precommit checks because it violates the 140-character line-length limit.

@jasontedor
Copy link
Copy Markdown
Member

@jbertouch The change looks great, thank you! There is one line that has to be fixed to meet the line-length limits or it will break the build on integration. There are also some lines where the indentation doesn't match our code style. I marked them in the PR review; do you mind fixing those too when you hit the line-length limit? It's fine if not, I'll handle them with an extra commit upon integration but since you have to push one more commit anyway I think you can hit them then? 😄

Finally, do you mind if I squash all of these commits into one when I integrate this PR?

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/Geo Indexing, search aggregations of geo points and shapes >enhancement v5.0.0-alpha2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants