Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve error messages #232

Merged
merged 7 commits into from
Jul 12, 2024
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,6 @@ node_modules/
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# exclude webstorm profile file
.idea/
gantunesr marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 8 additions & 6 deletions src/ledger-keyring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,14 @@ describe('LedgerKeyring', function () {
expect(keyring.hdk.publicKey).not.toBe('ABC');
});

it('throws an error when the bridge getPublicKey method throws an error and it is not an error type', async function () {
keyring.setHdPath(`m/44'/60'/0'/0`);
jest.spyOn(bridge, 'getPublicKey').mockRejectedValue('Some error');
await expect(keyring.unlock()).rejects.toThrow(
'Ledger Ethereum app closed. Open it to unlock.',
);
});

it('does not update hdk.publicKey if updateHdk is false', async function () {
// @ts-expect-error we want to bypass the publicKey property set method
keyring.hdk = { publicKey: 'ABC' };
Expand Down Expand Up @@ -366,12 +374,6 @@ describe('LedgerKeyring', function () {
.mockRejectedValue(new Error('Some error'));
await expect(keyring.unlock()).rejects.toThrow('Some error');
});

it('throws an error when the bridge getPublicKey method throws an error and it is not an error type', async function () {
keyring.setHdPath(`m/44'/60'/0'/0`);
jest.spyOn(bridge, 'getPublicKey').mockRejectedValue('Some error');
await expect(keyring.unlock()).rejects.toThrow('Unknown error');
});
});

describe('addAccounts', function () {
Expand Down
4 changes: 3 additions & 1 deletion src/ledger-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ export class LedgerKeyring extends EventEmitter {
hdPath: path,
});
} catch (error) {
throw error instanceof Error ? error : new Error('Unknown error');
throw error instanceof Error
? error
: new Error('Ledger Ethereum app closed. Open it to unlock.');
}

if (updateHdk && payload.chainCode) {
Expand Down
Loading