Skip to content

Commit

Permalink
Fabo/1573 sent errors via raven (#1624)
Browse files Browse the repository at this point in the history
* added exception catching by raven

* fixed test

* changelog

* fixed some tests

* improved coverage

* err to error
  • Loading branch information
faboweb authored and fedekunze committed Nov 22, 2018
1 parent 51e1b2e commit 3ee63cc
Show file tree
Hide file tree
Showing 22 changed files with 169 additions and 109 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- [\#1564](https://github.com/cosmos/voyager/issues/1564) Add support to query governance proposals on `lcdClient(Mock).js` @fedekunze
- [\#1544](https://github.com/cosmos/voyager/issues/1544) Added eslint-plugin-vue for cleaner vue files @jbibla
- [\#1611](https://github.com/cosmos/voyager/issues/1611) added no testnet warning @faboweb
- [\#1573](https://github.com/cosmos/voyager/issues/1573) added remote error collection for several catched errors in Voyager @faboweb

### Changed

Expand Down
3 changes: 3 additions & 0 deletions app/src/renderer/vuex/modules/blockchain.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Raven from "raven-js"

export default ({ node }) => {
const state = {
blockMetaInfo: { block_id: {} },
Expand Down Expand Up @@ -65,6 +67,7 @@ export default ({ node }) => {
title: `Error fetching block information`,
body: err.message
})
Raven.captureException(err)
state.loading = false
state.error = err
return null
Expand Down
36 changes: 20 additions & 16 deletions app/src/renderer/vuex/modules/connection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use strict"

import { ipcRenderer, remote } from "electron"
import Raven from "raven-js"
import { sleep } from "scripts/common.js"

const config = remote.getGlobal(`config`)
Expand Down Expand Up @@ -73,15 +72,15 @@ export default function({ node }) {
commit(`setNode`, node)

// TODO: get event from light-client websocket instead of RPC connection (once that exists)
node.rpc.on(`error`, err => {
if (err.message.indexOf(`disconnected`) !== -1) {
node.rpc.on(`error`, error => {
if (error.message.indexOf(`disconnected`) !== -1) {
commit(`setConnected`, false)
dispatch(`reconnect`)
}
})
node.rpc.status((err, res) => {
if (err) return console.error(err)
let status = res
node.rpc.status((error, result) => {
if (error) return console.error(error)
let status = result
dispatch(`setLastHeader`, {
height: status.sync_info.latest_block_height,
chain_id: status.node_info.network
Expand All @@ -90,9 +89,10 @@ export default function({ node }) {

node.rpc.subscribe(
{ query: `tm.event = 'NewBlockHeader'` },
(err, event) => {
if (err) {
return console.error(`error subscribing to headers`, err)
(error, event) => {
if (error) {
Raven.captureException(error)
return console.error(`error subscribing to headers`, error)
}
dispatch(`setLastHeader`, event.data.value.header)
}
Expand All @@ -119,7 +119,7 @@ export default function({ node }) {
commit(`setModalNodeHalted`, true)
},
async checkConnection({ commit }) {
let error = () =>
let errorHandler = () =>
commit(`notifyError`, {
title: `Critical Error`,
body: `Couldn't initialize the blockchain client. If the problem persists, please make an issue on GitHub.`
Expand All @@ -128,11 +128,11 @@ export default function({ node }) {
if (await node.lcdConnected()) {
return true
} else {
error()
errorHandler()
return false
}
} catch (err) {
error()
} catch (error) {
errorHandler()
return false
}
},
Expand All @@ -147,8 +147,12 @@ export default function({ node }) {
dispatch(`pollRPCConnection`)
}
}, timeout)
node.rpc.status(err => {
if (err) return console.error(`Couldn't get status via RPC:`, err)
node.rpc.status(error => {
if (error) {
Raven.captureException(error)
console.error(`Couldn't get status via RPC:`, error)
return
}

state.nodeTimeout = null
state.connected = true
Expand Down
11 changes: 6 additions & 5 deletions app/src/renderer/vuex/modules/delegates.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict"

import Raven from "raven-js"
import BN from "bignumber.js"
import { ratToBigNumber } from "scripts/common"
import num from "scripts/num"
import { isEmpty } from "lodash"
import b32 from "scripts/b32"

export default ({ node }) => {
const emptyState = {
delegates: [],
Expand Down Expand Up @@ -95,13 +95,14 @@ export default ({ node }) => {
dispatch(`updateSigningInfo`, validators)

return validators
} catch (err) {
} catch (error) {
commit(`notifyError`, {
title: `Error fetching validators`,
body: err.message
body: error.message
})
Raven.captureException(error)
commit(`setDelegateLoading`, false)
state.error = err
state.error = error
return []
}
},
Expand Down
11 changes: 6 additions & 5 deletions app/src/renderer/vuex/modules/delegation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict"

import Raven from "raven-js"
import { calculateShares } from "scripts/common"

export default ({ node }) => {
let emptyState = {
loading: false,
Expand Down Expand Up @@ -140,12 +140,13 @@ export default ({ node }) => {
})
})
state.loadedOnce = true
} catch (err) {
} catch (error) {
commit(`notifyError`, {
title: `Error fetching delegations`,
body: err.message
body: error.message
})
state.error = err
Raven.captureException(error)
state.error = error
}

state.loading = false
Expand Down
2 changes: 0 additions & 2 deletions app/src/renderer/vuex/modules/filters.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict"

export default () => {
const emptyState = {
balances: {
Expand Down
3 changes: 2 additions & 1 deletion app/src/renderer/vuex/modules/governance/deposits.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict"
import Raven from "raven-js"

export default ({ node }) => {
const state = {
Expand All @@ -24,6 +24,7 @@ export default ({ node }) => {
title: `Error fetching deposits on proposals`,
body: err.message
})
Raven.captureException(err)
state.error = err
}
state.loading = false
Expand Down
3 changes: 3 additions & 0 deletions app/src/renderer/vuex/modules/governance/parameters.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Raven from "raven-js"

export default ({ node }) => {
const emptyState = {
govParameters: {
Expand Down Expand Up @@ -30,6 +32,7 @@ export default ({ node }) => {
title: `Error fetching governance parameters`,
body: err.message
})
Raven.captureException(err)
state.error = err
}
state.loading = false
Expand Down
3 changes: 2 additions & 1 deletion app/src/renderer/vuex/modules/governance/proposals.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict"
import Raven from "raven-js"
import Vue from "vue"

export default ({ node }) => {
Expand Down Expand Up @@ -39,6 +39,7 @@ export default ({ node }) => {
title: `Error fetching proposals`,
body: err.message
})
Raven.captureException(err)
state.error = err
}
state.loading = false
Expand Down
3 changes: 2 additions & 1 deletion app/src/renderer/vuex/modules/governance/votes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict"
import Raven from "raven-js"

export default ({ node }) => {
const state = {
Expand All @@ -24,6 +24,7 @@ export default ({ node }) => {
title: `Error fetching votes`,
body: err.message
})
Raven.captureException(err)
state.error = err
}
state.loading = false
Expand Down
2 changes: 2 additions & 0 deletions app/src/renderer/vuex/modules/keybase.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from "axios"
import Raven from "raven-js"

export default ({}) => {
const emptyState = {
Expand Down Expand Up @@ -57,6 +58,7 @@ export default ({}) => {
title: `Error fetching keybase information for validators`,
body: err.message
})
Raven.captureException(err)
state.error = err
}
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/renderer/vuex/modules/parameters.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Raven from "raven-js"

export default ({ node }) => {
const emptyState = {
parameters: {},
Expand All @@ -23,6 +25,7 @@ export default ({ node }) => {
title: `Error fetching staking parameters`,
body: err.message
})
Raven.captureException(err)
state.error = err
}
state.loading = false
Expand Down
3 changes: 2 additions & 1 deletion app/src/renderer/vuex/modules/pool.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict"
import Raven from "raven-js"

export default ({ node }) => {
const emptyState = {
Expand Down Expand Up @@ -30,6 +30,7 @@ export default ({ node }) => {
title: `Error fetching staking pool information`,
body: err.message
})
Raven.captureException(err)
state.error = err
}
state.loading = false
Expand Down
2 changes: 0 additions & 2 deletions app/src/renderer/vuex/modules/send.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict"

export default ({ node }) => {
let lock = null

Expand Down
62 changes: 27 additions & 35 deletions app/src/renderer/vuex/modules/transactions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fp = require(`lodash/fp`)
import fp from "lodash/fp"
import { uniqBy } from "lodash"
import Raven from "raven-js"
export default ({ node }) => {
let emptyState = {
loading: false,
Expand All @@ -26,9 +27,6 @@ export default ({ node }) => {
setHistoryLoading(state, loading) {
state.loading = loading
},
setError(state, error) {
state.error = error
},
setTransactionTime(state, { blockHeight, blockMetaInfo }) {
txCategories.forEach(category => {
state[category].forEach(t => {
Expand All @@ -50,10 +48,10 @@ export default ({ node }) => {
await dispatch(`getAllTxs`)
}
},
async getAllTxs({ commit, dispatch }) {
commit(`setHistoryLoading`, true)

async getAllTxs({ commit, dispatch, state }) {
try {
commit(`setHistoryLoading`, true)

const stakingTxs = await dispatch(`getTx`, `staking`)
commit(`setStakingTxs`, stakingTxs)

Expand All @@ -68,45 +66,39 @@ export default ({ node }) => {
transactions: allTxs
})
} catch (error) {
commit(`setError`, error.message.slice(0))
commit(`notifyError`, {
title: `Error getting transactions`,
body: error.message
})
Raven.captureException(error)
state.error = error
}
commit(`setHistoryLoading`, false)
},
async getTx(
{
rootState: {
user: { address }
},
commit
}
},
type
) {
try {
let response
switch (type) {
case `staking`:
response = await node.getDelegatorTxs(address)
break
case `governance`:
response = await node.getGovernanceTxs(address)
break
case `wallet`:
response = await node.txs(address)
break
default:
throw new Error(`Unknown transaction type`)
}
state.error = null
const transactionsPlusType = response.map(fp.set(`type`, type))
return response ? uniqBy(transactionsPlusType, `hash`) : []
} catch (err) {
commit(`notifyError`, {
title: `Error fetching ${type} transactions`,
body: err.message
})
state.error = err
return []
let response
switch (type) {
case `staking`:
response = await node.getDelegatorTxs(address)
break
case `governance`:
response = await node.getGovernanceTxs(address)
break
case `wallet`:
response = await node.txs(address)
break
default:
throw new Error(`Unknown transaction type`)
}
const transactionsPlusType = response.map(fp.set(`type`, type))
return response ? uniqBy(transactionsPlusType, `hash`) : []
},
async enrichTransactions({ dispatch }, { transactions }) {
const blockHeights = new Set(transactions.map(({ height }) => height))
Expand Down
Loading

0 comments on commit 3ee63cc

Please sign in to comment.