Skip to content

Commit

Permalink
fix(askar): custom error handling (#1372)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <timo@animo.id>
  • Loading branch information
TimoGlastra committed Mar 8, 2023
1 parent 39c4ed0 commit c72ba14
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 43 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
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -876,23 +876,23 @@
resolved "https://registry.yarnpkg.com/@hyperledger/anoncreds-shared/-/anoncreds-shared-0.1.0-dev.6.tgz#2e6afb4641cc25daef4074a32990ec078d2fd94e"
integrity sha512-4YZ2kzhOOrGRL//n/Qe/A+yyGsbnHqojQW6vGEZQpZ9bf4ir+QaZLRHijgXFmffMA+SRONfdlnxhLJ6/b6ZaMg==

"@hyperledger/aries-askar-nodejs@^0.1.0-dev.3":
version "0.1.0-dev.3"
resolved "https://registry.yarnpkg.com/@hyperledger/aries-askar-nodejs/-/aries-askar-nodejs-0.1.0-dev.3.tgz#19ecff41f81525efea8212a3ad6b8c3db11950c4"
integrity sha512-9hnCNWxIRkLP793P4DuZAJRWfxf1v6NdQyEgoMdNletcP7KAf/YfBqySTYGqA6TIiMu/abNrmq+WsHkK0yyZ+g==
"@hyperledger/aries-askar-nodejs@^0.1.0-dev.4":
version "0.1.0-dev.4"
resolved "https://registry.yarnpkg.com/@hyperledger/aries-askar-nodejs/-/aries-askar-nodejs-0.1.0-dev.4.tgz#016f89886732366eff9cba54eb6fcbf02cc5a212"
integrity sha512-Wh1SoxakBpQvgbFrLq+NIJ0l02N8SjBRDZBs/c55gIeenXzDJY/ZgfM6faLdDv4XeE6agXd4yl35f4s7+3zK+Q==
dependencies:
"@hyperledger/aries-askar-shared" "0.1.0-dev.3"
"@hyperledger/aries-askar-shared" "0.1.0-dev.4"
"@mapbox/node-pre-gyp" "^1.0.10"
ffi-napi "^4.0.3"
node-cache "^5.1.2"
ref-array-di "^1.2.2"
ref-napi "^3.0.3"
ref-struct-di "^1.1.1"

"@hyperledger/aries-askar-shared@0.1.0-dev.3", "@hyperledger/aries-askar-shared@^0.1.0-dev.3":
version "0.1.0-dev.3"
resolved "https://registry.yarnpkg.com/@hyperledger/aries-askar-shared/-/aries-askar-shared-0.1.0-dev.3.tgz#2056db8c0671ec4b1e926e1491fdca9357ede633"
integrity sha512-LIRyCg2PK6wN483Bdzq4eJmQ2LNCCRq2g7GF4yv+H+V04ky7hdeoJbSKN8lYr/OQn1tS6ALx9p2ArvAt7pTfVw==
"@hyperledger/aries-askar-shared@0.1.0-dev.4", "@hyperledger/aries-askar-shared@^0.1.0-dev.4":
version "0.1.0-dev.4"
resolved "https://registry.yarnpkg.com/@hyperledger/aries-askar-shared/-/aries-askar-shared-0.1.0-dev.4.tgz#439fbaa3911be56c134cbacfddd1553eb0b06dde"
integrity sha512-z+bWVbFD3S7IuYlG2XTxCjyaJWmS/wiHtYRxgWXjF6o4iR2vW+/y0NhTpiX2gO4Gx62zxFfh50b0oQTOM6/XqQ==
dependencies:
fast-text-encoding "^1.0.3"

Expand Down

0 comments on commit c72ba14

Please sign in to comment.