mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-20 06:07:57 +00:00
Make mixpanelTrack nicely handle errors being passed in and use it for logging bootstrapping errors.
This commit is contained in:
parent
f43afd4a95
commit
5bb552f065
@ -40,7 +40,7 @@ knex('config').select('value').where(key: 'uuid').then ([ uuid ]) ->
|
||||
retryingBootstrap = ->
|
||||
utils.mixpanelTrack('Device bootstrap')
|
||||
bootstrap().catch (err) ->
|
||||
utils.mixpanelTrack("Device bootstrap failed due to #{err?.message}, retrying in #{config.bootstrapRetryDelay}ms")
|
||||
utils.mixpanelTrack('Device bootstrap failed, retrying', {error: err, delay: config.bootstrapRetryDelay})
|
||||
Promise.delay(config.bootstrapRetryDelay)
|
||||
.then(retryingBootstrap)
|
||||
retryingBootstrap()
|
||||
|
@ -18,6 +18,17 @@ exports.mixpanelProperties = mixpanelProperties =
|
||||
username: require('/boot/config.json').username
|
||||
|
||||
exports.mixpanelTrack = (event, properties = {}) ->
|
||||
# Allow passing in an error directly and having it assigned to the error property.
|
||||
if properties instanceof Error
|
||||
properties = error: properties
|
||||
|
||||
# If the properties has an error argument that is an Error object then it treats it nicely,
|
||||
# rather than letting it become `{}`
|
||||
if properties.error instanceof Error
|
||||
properties.error =
|
||||
message: properties.error.message
|
||||
stack: properties.error.stack
|
||||
|
||||
console.log('Event:', event, JSON.stringify(properties))
|
||||
# Mutation is bad, and it should feel bad
|
||||
properties = _.assign(_.cloneDeep(properties), mixpanelProperties)
|
||||
|
Loading…
Reference in New Issue
Block a user