Skip to content

Commit

Permalink
handle unknown index types gracefully in iUtils
Browse files Browse the repository at this point in the history
this updates parseTaskId in iUtils.coffee which uses a somwhat strict
regular expression to parse a given task id and extract type,
datasource, and time.

this simply removes throwing the error and falls back to 'other' for
type leaving dataSource and dataTime alone. in case of a match failure,
they would just default to undefined which isn't a blocker to render
/indexing-service view.
  • Loading branch information
alperkokmen committed Oct 11, 2018
1 parent 117cc36 commit ea4f4db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
9 changes: 2 additions & 7 deletions src/client/factories/iUtils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ moment = require '../../../bower_components/moment/min/moment.min.js'

module.exports = ->
parseTaskId: (taskId) ->
m = taskId.match /^(?:(hadoop_convert_segment)|index_(hadoop|realtime|spark)|(archive))_(.+)_(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z)/
type = m[3]
type ||= m[2]
type ||= m[1]

throw Error("Can't parse #{taskId}") unless m
m = taskId.match(/^(?:(hadoop_convert_segment)|index_(hadoop|realtime|spark)|(archive))_(.+)_(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z)/) || []
{
id: taskId
type
type: m[3] || m[2] || m[1] || 'other'
dataSource: m[4]
dataTime: m[5]
}
Expand Down
11 changes: 8 additions & 3 deletions test/unit/factories/iUtils.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ describe '$iUtils', () ->
dataTime: $taskTimestamp
})

it 'should throw an error if taskId does not match expected pattern', () ->
expect(() -> $iUtils.parseTaskId('index_kafka_twitter_1675e770de9a423_hfdhgjko'))
.toThrow(new TypeError("Cannot read property '3' of null"))
it 'should not throw an error if taskId does not match expected pattern', () ->
task = $iUtils.parseTaskId('index_kafka_twitter_1675e770de9a423_hfdhgjko')
expect(task).toEqual({
id: 'index_kafka_twitter_1675e770de9a423_hfdhgjko'
type: 'other'
dataSource: undefined
dataTime: undefined
})

0 comments on commit ea4f4db

Please sign in to comment.