Skip to content

Commit

Permalink
fix(askar): custom error handling (openwallet-foundation#1372)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <timo@animo.id>
  • Loading branch information
TimoGlastra authored and karimStekelenburg committed Mar 17, 2023
1 parent a9ce47f commit c567dca
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 36 deletions.
4 changes: 2 additions & 2 deletions packages/askar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"dependencies": {
"@aries-framework/core": "0.3.3",
"@hyperledger/aries-askar-shared": "^0.1.0-dev.3",
"@hyperledger/aries-askar-shared": "^0.1.0-dev.4",
"bn.js": "^5.2.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
Expand All @@ -34,7 +34,7 @@
},
"devDependencies": {
"@types/bn.js": "^5.1.0",
"@hyperledger/aries-askar-nodejs": "^0.1.0-dev.3",
"@hyperledger/aries-askar-nodejs": "^0.1.0-dev.4",
"reflect-metadata": "^0.1.13",
"rimraf": "^4.0.7",
"typescript": "~4.9.4"
Expand Down
18 changes: 1 addition & 17 deletions packages/askar/src/storage/AskarStorageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,7 @@ export class AskarStorageService<T extends BaseRecord> implements StorageService
}
return recordToInstance(record, recordClass)
} catch (error) {
if (
isAskarError(error) &&
(error.code === AskarErrorCode.NotFound ||
// FIXME: this is current output from askar wrapper but does not describe specifically a not found scenario
error.message === 'Received null pointer. The native library could not find the value.')
) {
throw new RecordNotFoundError(`record with id ${id} not found.`, {
recordType: recordClass.type,
cause: error,
})
}
if (error instanceof RecordNotFoundError) throw error
throw new WalletError(`Error getting record`, { cause: error })
}
}
Expand Down Expand Up @@ -169,12 +159,6 @@ export class AskarStorageService<T extends BaseRecord> implements StorageService
}
return instances
} catch (error) {
if (
isAskarError(error) && // FIXME: this is current output from askar wrapper but does not describe specifically a 0 length scenario
error.message === 'Received null pointer. The native library could not find the value.'
) {
return instances
}
throw new WalletError(`Error executing query`, { cause: error })
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describeRunInNodeVersion([18], 'AskarStorageService', () => {
forUpdate: false,
})

expect(JSON.parse(retrieveRecord.getTags(0))).toEqual({
expect(JSON.parse(retrieveRecord?.getTags(0) ?? '{}')).toEqual({
someBoolean: '1',
someOtherBoolean: '0',
someStringValue: 'string',
Expand Down
12 changes: 0 additions & 12 deletions packages/askar/src/wallet/AskarWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
isValidSeed,
isValidPrivateKey,
JsonTransformer,
RecordNotFoundError,
WalletInvalidKeyError,
WalletDuplicateError,
JsonEncoder,
Expand Down Expand Up @@ -715,17 +714,6 @@ export class AskarWallet implements Wallet {
throw new WalletError(`No content found for record with public key: ${publicKeyBase58}`)
}
} catch (error) {
if (
isAskarError(error) &&
(error.code === AskarErrorCode.NotFound ||
// FIXME: this is current output from askar wrapper but does not describe specifically a not found scenario
error.message === 'Received null pointer. The native library could not find the value.')
) {
throw new RecordNotFoundError(`KeyPairRecord not found for public key: ${publicKeyBase58}.`, {
recordType: 'KeyPairRecord',
cause: error,
})
}
throw new WalletError('Error retrieving KeyPair record', { cause: error })
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/askar/src/wallet/__tests__/AskarWallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ describe.skip('Currently, all KeyTypes are supported by Askar natively', () => {
})
})

describe('AskarWallet management', () => {
describeRunInNodeVersion([18], 'AskarWallet management', () => {
let askarWallet: AskarWallet

afterEach(async () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/askar/tests/askar-postgres.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { ConnectionRecord } from '@aries-framework/core'
import { Agent, HandshakeProtocol } from '@aries-framework/core'
import { Subject } from 'rxjs'

import { describeRunInNodeVersion } from '../../../tests/runInVersion'
import { SubjectInboundTransport } from '../../../tests/transport/SubjectInboundTransport'
import { SubjectOutboundTransport } from '../../../tests/transport/SubjectOutboundTransport'
import { waitForBasicMessage } from '../../core/tests/helpers'
Expand All @@ -31,7 +32,7 @@ const bobPostgresAgentOptions = getPostgresAgentOptions('AgentsBob', storageConf
})

// FIXME: Re-include in tests when Askar NodeJS wrapper performance is improved
describe.skip('Askar Postgres agents', () => {
describeRunInNodeVersion([18], 'Askar Postgres agents', () => {
let aliceAgent: Agent
let bobAgent: Agent
let aliceConnection: ConnectionRecord
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@
resolved "https://registry.yarnpkg.com/@hyperledger/anoncreds-shared/-/anoncreds-shared-0.1.0-dev.10.tgz#9d67f64e98ff41971644c95b03dabafd741df4df"
integrity sha512-POvcwQrUcPrwoZehQa38pN1dnjyeUlrQ6VlksbBRS8SUHJuyixZsD+d3XoumqaNfl9Z1DCjfuOgEiPlec01gXQ==

"@hyperledger/aries-askar-nodejs@^0.1.0-dev.3":
"@hyperledger/aries-askar-nodejs@^0.1.0-dev.4":
version "0.1.0-dev.5"
resolved "https://registry.yarnpkg.com/@hyperledger/aries-askar-nodejs/-/aries-askar-nodejs-0.1.0-dev.5.tgz#602db32f49dd1f9e7f83d378a9813d2bde5886f8"
integrity sha512-38lXtmnhhca+s14V3zTefAyZGIg6nRpKi4Emnr1q5hQXmn1WZn7/ybYJbcI/VHoAPNLA+DydSI99U5KuPkrC1w==
Expand All @@ -908,7 +908,7 @@
ref-napi "^3.0.3"
ref-struct-di "^1.1.1"

"@hyperledger/aries-askar-shared@0.1.0-dev.5", "@hyperledger/aries-askar-shared@^0.1.0-dev.3":
"@hyperledger/aries-askar-shared@0.1.0-dev.5", "@hyperledger/aries-askar-shared@^0.1.0-dev.4":
version "0.1.0-dev.5"
resolved "https://registry.yarnpkg.com/@hyperledger/aries-askar-shared/-/aries-askar-shared-0.1.0-dev.5.tgz#06ae815b873693b7b483004d027059d50f24fb60"
integrity sha512-nufXqMslytelijC0uXBTuaj9OHjHo5mJe0hABKfYJqe9p1RYmmKlnqi+B/mjWrr2R8yG8NLrNnHbwPcBArLrPA==
Expand Down

0 comments on commit c567dca

Please sign in to comment.