Skip to content

Commit

Permalink
Merge pull request #1888 from okTurtles/side-effect-errors-logging
Browse files Browse the repository at this point in the history
Fix #1861
  • Loading branch information
taoeffect authored Mar 15, 2024
2 parents d0e4f6d + a41bbf1 commit 20d32d2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
2 changes: 0 additions & 2 deletions frontend/controller/actions/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export const encryptedAction = (
return await sm()
}
} catch (e) {
console.error(`${action} failed!`, e)
const userFacingErrStr = typeof humanError === 'string'
? `${humanError} ${LError(e).reportError}`
: humanError(params, e)
Expand Down Expand Up @@ -239,7 +238,6 @@ export const encryptedNotification = (
return await sm()
}
} catch (e) {
console.error(`${action} failed!`, e)
const userFacingErrStr = typeof humanError === 'string'
? `${humanError} ${LError(e).reportError}`
: humanError(params, e)
Expand Down
35 changes: 19 additions & 16 deletions frontend/model/contracts/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,18 @@ const leaveChatRoomAction = (state, chatRoomID, memberID, actorID, leavingGroup)
leavingGroup &&
(e?.name === 'ChelErrorSignatureKeyNotFound' || (
e?.name === 'GIErrorUIRuntimeError' &&
['ChelErrorSignatureKeyNotFound', 'GIErrorMissingSigningKeyError'].includes(e?.cause?.name)
(
['ChelErrorSignatureKeyNotFound', 'GIErrorMissingSigningKeyError'].includes(e?.cause?.name) ||
(e?.cause?.name === 'Error' && e.cause.message.endsWith('is not part of'))
)
))
) {
// This is fine; it just means we were removed by someone else
return
}
throw e
}).catch((e) => {
console.error('[gi.contracts/group] Error sending chatroom leave action', e)
console.warn('[gi.contracts/group] Error sending chatroom leave action', e)
})
}

Expand Down Expand Up @@ -1067,7 +1070,7 @@ sbp('chelonia/defineContract', {
// Put this invocation at the end of a sync to ensure that leaving and
// re-joining works
sbp('chelonia/queueInvocation', contractID, () => sbp('gi.contracts/group/leaveGroup', { data, meta, contractID, getters, height, innerSigningContractID })).catch(e => {
console.error(`[gi.contracts/group/removeMember/sideEffect] Error ${e.name} during queueInvocation for ${contractID}`, e)
console.warn(`[gi.contracts/group/removeMember/sideEffect] Error ${e.name} during queueInvocation for ${contractID}`, e)
})
}
},
Expand Down Expand Up @@ -1192,8 +1195,8 @@ sbp('chelonia/defineContract', {
memberID: innerSigningContractID
})
}
}).catch(() => {
console.error(`Error subscribing to identity contract ${innerSigningContractID} of group member for group ${contractID}`)
}).catch((e) => {
console.error(`Error subscribing to identity contract ${innerSigningContractID} of group member for group ${contractID}`, e)
})
}
}).catch(e => {
Expand Down Expand Up @@ -1464,7 +1467,7 @@ sbp('chelonia/defineContract', {
// the relevant action to the chatroom contract
if (innerSigningContractID === rootState.loggedIn.identityContractID) {
sbp('chelonia/queueInvocation', contractID, () => sbp('gi.contracts/group/joinGroupChatrooms', contractID, data.chatRoomID, memberID)).catch((e) => {
console.error(`[gi.contracts/group/joinChatRoom/sideEffect] Error adding member to group chatroom for ${contractID}`, { e, data })
console.warn(`[gi.contracts/group/joinChatRoom/sideEffect] Error adding member to group chatroom for ${contractID}`, { e, data })
})
} else if (memberID === rootState.loggedIn.identityContractID) {
// If we were the ones added to the chatroom, we sync the chatroom.
Expand All @@ -1488,7 +1491,7 @@ sbp('chelonia/defineContract', {
// we won't need this special key.
sbp('okTurtles.data/set', `JOINING_CHATROOM-${data.chatRoomID}-${memberID}`, true)
sbp('chelonia/contract/sync', data.chatRoomID).catch((e) => {
console.error(`[gi.contracts/group/joinChatRoom/sideEffect] Error syncing chatroom contract for ${contractID}`, { e, data })
console.warn(`[gi.contracts/group/joinChatRoom/sideEffect] Error syncing chatroom contract for ${contractID}`, { e, data })
})
}
})
Expand Down Expand Up @@ -1615,7 +1618,7 @@ sbp('chelonia/defineContract', {
groupContractID: contractID
}
}).catch(e => {
console.error(`[gi.contracts/group/_cleanup] ${e.name} thrown by gi.contracts/identity/leaveGroup ${identityContractID} for ${contractID}:`, e)
console.warn(`[gi.contracts/group/_cleanup] ${e.name} thrown by gi.contracts/identity/leaveGroup ${identityContractID} for ${contractID}:`, e)
})
// this looks crazy, but doing this was necessary to fix a race condition in the
// group-member-removal Cypress tests where due to the ordering of asynchronous events
Expand All @@ -1627,15 +1630,15 @@ sbp('chelonia/defineContract', {
const switchFrom = router.currentRoute.path
const switchTo = rootState.currentGroupId ? '/dashboard' : '/'
if (switchFrom !== '/join' && switchFrom !== switchTo) {
router.push({ path: switchTo }).catch(console.warn)
router.push({ path: switchTo }).catch((e) => console.error('Error switching groups', e))
}
})
.catch(e => {
console.error(`gi.contracts/group/_cleanup: ${e.name} thrown updating routes:`, e)
})
.then(() => sbp('gi.contracts/group/revokeGroupKeyAndRotateOurPEK', contractID, true))
.catch(e => {
console.error(`gi.contracts/group/_cleanup: ${e.name} thrown during revokeGroupKeyAndRotateOurPEK to ${contractID}:`, e)
console.warn(`gi.contracts/group/_cleanup: ${e.name} thrown during revokeGroupKeyAndRotateOurPEK to ${contractID}:`, e)
})
// TODO - #828 remove other group members contracts if applicable
},
Expand Down Expand Up @@ -1814,7 +1817,7 @@ sbp('chelonia/defineContract', {
}
}
}).catch(e => {
console.error(`Unable to join ${memberID} to chatroom ${chatRoomId} for group ${contractID}`, e)
console.warn(`Unable to join ${memberID} to chatroom ${chatRoomId} for group ${contractID}`, e)
})
} finally {
await sbp('chelonia/contract/remove', chatRoomId, { removeIfPending: true })
Expand Down Expand Up @@ -1890,7 +1893,7 @@ sbp('chelonia/defineContract', {
} */

leaveAllChatRoomsUponLeaving(state, memberID, innerSigningContractID).catch((e) => {
console.error('[gi.contracts/group/leaveGroup]: Error while leaving all chatrooms', e)
console.warn('[gi.contracts/group/leaveGroup]: Error while leaving all chatrooms', e)
})

if (memberID === identityContractID) {
Expand All @@ -1917,7 +1920,7 @@ sbp('chelonia/defineContract', {
.then(() => sbp('gi.contracts/group/rotateKeys', contractID))
.then(() => sbp('gi.contracts/group/revokeGroupKeyAndRotateOurPEK', contractID, false))
.catch((e) => {
console.error(`[gi.contracts/group/leaveGroup] for ${contractID}: Error rotating group keys or our PEK`, e)
console.warn(`[gi.contracts/group/leaveGroup] for ${contractID}: Error rotating group keys or our PEK`, e)
})

sbp('gi.contracts/group/removeForeignKeys', contractID, memberID, state)
Expand Down Expand Up @@ -1970,17 +1973,17 @@ sbp('chelonia/defineContract', {
signingKeyId: CSKid
}])
.catch(e => {
console.error(`revokeGroupKeyAndRotateOurPEK: ${e.name} thrown during keyDel to ${identityContractID}:`, e)
console.warn(`revokeGroupKeyAndRotateOurPEK: ${e.name} thrown during keyDel to ${identityContractID}:`, e)
})
}

sbp('chelonia/queueInvocation', identityContractID, ['chelonia/contract/disconnect', identityContractID, groupContractID]).catch(e => {
console.error(`revokeGroupKeyAndRotateOurPEK: ${e.name} thrown during queueEvent to ${identityContractID}:`, e)
console.warn(`revokeGroupKeyAndRotateOurPEK: ${e.name} thrown during queueEvent to ${identityContractID}:`, e)
})
}

sbp('chelonia/queueInvocation', identityContractID, ['gi.actions/out/rotateKeys', identityContractID, 'gi.contracts/identity', 'pending', 'gi.actions/identity/shareNewPEK']).catch(e => {
console.error(`revokeGroupKeyAndRotateOurPEK: ${e.name} thrown during queueEvent to ${identityContractID}:`, e)
console.warn(`revokeGroupKeyAndRotateOurPEK: ${e.name} thrown during queueEvent to ${identityContractID}:`, e)
})
},
'gi.contracts/group/removeForeignKeys': (contractID, userID, state) => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/model/contracts/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ sbp('chelonia/defineContract', {
innerSigningKeyId: sbp('chelonia/contract/currentKeyIdByName', state, 'csk'),
encryptionKeyId: sbp('chelonia/contract/currentKeyIdByName', state, 'cek')
}).catch(e => {
console.error(`[gi.contracts/identity/joinGroup/sideEffect] Error sending gi.actions/group/join action for group ${data.groupContractID}`, e)
console.warn(`[gi.contracts/identity/joinGroup/sideEffect] Error sending gi.actions/group/join action for group ${data.groupContractID}`, e)
})
}).catch(e => {
console.error(`[gi.contracts/identity/joinGroup/sideEffect] Error at queueInvocation group ${data.groupContractID}`, e)
Expand Down Expand Up @@ -295,7 +295,7 @@ sbp('chelonia/defineContract', {
sbp('gi.actions/group/removeOurselves', {
contractID: groupContractID
}).catch(e => {
console.error(`[gi.contracts/identity/leaveGroup/sideEffect] Error removing ourselves from group contract ${data.groupContractID}`, e)
console.warn(`[gi.contracts/identity/leaveGroup/sideEffect] Error removing ourselves from group contract ${data.groupContractID}`, e)
})
}

Expand Down
9 changes: 6 additions & 3 deletions shared/domains/chelonia/internals.js
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ export default (sbp('sbp/selectors/register', {
if (!foreignState) return acc
const fKeyId = findKeyIdByName(foreignState, foreignKeyName)
if (!fKeyId) {
// Key was deleted
// Key was deleted; mark it for deletion
pendingKeyRevocations.find(([id]) => id === keyId)[1] = 'del'
return acc
}
Expand All @@ -1364,10 +1364,13 @@ export default (sbp('sbp/selectors/register', {
})
return [currentRingLevel, currentSigningKeyId, currentKeyArgs]
} else if (Number.isFinite(ringLevel)) {
const signingKeyId = findSuitableSecretKeyId(contractState, [GIMessage.OP_KEY_DEL], ['sig'], ringLevel)
const signingKeyId = findSuitableSecretKeyId(contractState, [GIMessage.OP_KEY_UPDATE], ['sig'], ringLevel)
if (signingKeyId) {
(currentKeyArgs: any).push({
keyId
name: key.name,
oldKeyId: keyId,
id: fKeyId,
data: foreignState._vm.authorizedKeys[fKeyId].data
})
return [ringLevel, signingKeyId, currentKeyArgs]
}
Expand Down

0 comments on commit 20d32d2

Please sign in to comment.