Skip to content

Commit

Permalink
bug: working out why errors arent being caught by expect
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Aug 26, 2024
1 parent 497e0e5 commit 2787ac0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
23 changes: 12 additions & 11 deletions src/client/handlers/VaultsSecretsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,23 @@ class VaultsSecretsList extends ServerHandler<
void,
void
> {
let files: Array<string>;
let files;
try {
// @ts-ignore: While the types don't fully match, it matches enough for our usage.
files = await fs.promises.readdir(input.path);
files = await fs.promises.readdir(input.secretName);
} catch (e) {
throw new clientErrors.ErrorClientFSReadFailed(
`No matches exist for path: ${input.secretPath}`,
{ cause: e },
);
// throw new clientErrors.ErrorClientFSReadFailed(e.message, {
// cause: e,
// });
// const er = new Error('Message of error');
// console.error('error from handler', er);
// throw er;
throw e;
}
files = files.map((file) => path.join(input.secretPath, file));

for await (const file of files) {
const stat = await fs.promises.stat(file);
const filePath = path.join(input.secretName, file.toString());
const stat = await fs.promises.stat(filePath);
const type = stat.isFile() ? 'FILE' : 'DIRECTORY';
yield { path: file, type: type };
yield { path: filePath, type: type };
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ type VaultsLatestVersionMessage = {

// Secrets
type SecretPathMessage = {
secretPath: string;
secretName: string;
};

type SecretIdentifierMessage = VaultIdentifierMessage & SecretPathMessage;
Expand Down
26 changes: 16 additions & 10 deletions tests/client/handlers/vaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Logger, { formatting, LogLevel, StreamHandler } from '@matrixai/logger';
import { DB } from '@matrixai/db';
import { RPCClient } from '@matrixai/rpc';
import { WebSocketClient } from '@matrixai/ws';
import { ErrorEncryptedFSError } from 'encryptedfs/dist/errors';
import TaskManager from '@/tasks/TaskManager';
import ACL from '@/acl/ACL';
import KeyRing from '@/keys/KeyRing';
Expand Down Expand Up @@ -69,7 +70,6 @@ import * as nodesUtils from '@/nodes/utils';
import * as vaultsUtils from '@/vaults/utils';
import * as vaultsErrors from '@/vaults/errors';
import * as networkUtils from '@/network/utils';
import * as clientErrors from '@/client/errors';
import * as testsUtils from '../../utils';

describe('vaultsClone', () => {
Expand Down Expand Up @@ -1589,21 +1589,27 @@ describe('vaultsSecretsNewDir and vaultsSecretsList', () => {
});
expect(addResponse.success).toBeTruthy();

await expect(async () => {
const files = await rpcClient.methods.vaultsSecretsList({
nameOrId: vaultsIdEncoded,
path: 'doesntExist',
});
const noFiles = await rpcClient.methods.vaultsSecretsList({
nameOrId: vaultsIdEncoded,
secretName: 'alsdfjpaosdifhpaos',
});

console.log('before expect')
await expect((async () => {
try {
for await (const _ of files); // Consume values
for await (const f of noFiles) {
console.log(`file: ${f}`);
};
} catch (e) {
throw e.cause;
console.error('error from test', e);
throw e;
}
}).rejects.toThrow(clientErrors.ErrorClientFSReadFailed);
})()).rejects.toThrow(Error);
console.log('after expect')

const secrets = await rpcClient.methods.vaultsSecretsList({
nameOrId: vaultsIdEncoded,
path: 'secretDir',
secretName: 'secretDir',
});

// Extract secret file paths
Expand Down

0 comments on commit 2787ac0

Please sign in to comment.