Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Nov 5, 2024
1 parent 2f29030 commit 5463208
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 78 deletions.
51 changes: 16 additions & 35 deletions src/network/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,51 +572,32 @@ function toError(
}
}
const eClass = errors[errorData.type];
let e: any;
// If the error is a Polykey error, then we can instantiate that error.
// Otherwise, do special processing for non-Polykey errors.
if (eClass != null) {
e = eClass.fromJSON(errorData);
const e = eClass.fromJSON(errorData);
if (errorData.data != null && 'cause' in errorData.data) {
e.cause = toError(errorData.data.cause, clientMetadata, false);
}
} else {
// If we are at the top and we encounter an unwrapped error, then wrap it
// inside a `ErrorPolykeyUnexpected`. This will allow wrapping the error
// inside a `ErrorPolykeyRemote` and be properly transferred over the RPC.
// Otherwise, if we are not at the top, then it must mean that we are
// encountering an already-wrapped error. Return the error as-is.
if (top) {
e = new errors.ErrorPolykeyUnexpected(
`Unexpected error of type ${errorData.type} occured`,
const remoteError = new networkErrors.ErrorPolykeyRemote(
{
cause: toError(errorData, clientMetadata, false),
localHost: clientMetadata.localHost,
localPort: clientMetadata.localPort,
remoteHost: clientMetadata.remoteHost,
remotePort: clientMetadata.remotePort,
command: clientMetadata.command,
},
undefined,
{
cause: e,
},
);
if (remoteError.cause instanceof ErrorPolykey) {
remoteError.exitCode = remoteError.cause.exitCode;
}
return remoteError;
} else {
return errorData;
}
}
if (top) {
const remoteError = new networkErrors.ErrorPolykeyRemote(
{
localHost: clientMetadata.localHost,
localPort: clientMetadata.localPort,
remoteHost: clientMetadata.remoteHost,
remotePort: clientMetadata.remotePort,
command: clientMetadata.command,
},
undefined,
{
cause: e,
},
);
if (remoteError.cause instanceof ErrorPolykey) {
remoteError.exitCode = remoteError.cause.exitCode;
return e;
}
return remoteError;
} else {
return e;
}
}
// Other values are returned as-is
Expand Down
45 changes: 2 additions & 43 deletions tests/client/handlers/vaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2082,8 +2082,8 @@ describe('vaultsSecretsGet', () => {
await vaultManager.withVaults([vaultId], async (vault) => {
await vault.writeF(async (efs) => {
await efs.mkdir(secretName);
})
})
});
});
// Cat file
const response = await rpcClient.methods.vaultsSecretsGet({
nameOrId: vaultsUtils.encodeVaultId(vaultId),
Expand Down Expand Up @@ -2296,47 +2296,6 @@ describe('vaultsSecretsRemove', () => {
vaultsSecretsRemove: typeof vaultsSecretsRemove;
}>;
let vaultManager: VaultManager;
// // Helper function to create secrets in a vault
// const createVaultSecret = async (
// vaultId: VaultId,
// secretName: string,
// content: string,
// ) => {
// await vaultManager.withVaults([vaultId], async (vault) => {
// await vault.writeF(async (efs) => {
// await efs.writeFile(secretName, content);
// expect(await efs.exists(secretName)).toBeTruthy();
// });
// });
// };
// // Helper function to ensure each file path was deleted
// const checkSecretIsDeleted = async (vaultId: VaultId, secretName: string) => {
// await vaultManager.withVaults([vaultId], async (vault) => {
// await vault.readF(async (efs) => {
// expect(await efs.exists(secretName)).toBeFalsy();
// });
// });
// };
// // Helper function to ensure each file path exists in the vault
// const checkSecretExists = async (vaultId: VaultId, secretName: string) => {
// await vaultManager.withVaults([vaultId], async (vault) => {
// await vault.readF(async (efs) => {
// expect(await efs.exists(secretName)).toBeTruthy();
// });
// });
// };
// // Helper function to create a directory
// const createVaultDir = async (
// vaultId: VaultId,
// dirName: string,
// recursive: boolean = false,
// ) => {
// await vaultManager.withVaults([vaultId], async (vault) => {
// await vault.writeF(async (efs) => {
// await efs.mkdir(dirName, { recursive: recursive });
// });
// });
// };
beforeEach(async () => {
dataDir = await fs.promises.mkdtemp(
path.join(os.tmpdir(), 'polykey-test-'),
Expand Down

0 comments on commit 5463208

Please sign in to comment.