From 5463208605022382c673f306ecb78c7dcbb25df4 Mon Sep 17 00:00:00 2001 From: Aryan Jassal Date: Tue, 5 Nov 2024 15:57:06 +1100 Subject: [PATCH] chore: cleanup --- src/network/utils.ts | 51 +++++++++------------------- tests/client/handlers/vaults.test.ts | 45 ++---------------------- 2 files changed, 18 insertions(+), 78 deletions(-) diff --git a/src/network/utils.ts b/src/network/utils.ts index 5379f2859..2d3ed1439 100644 --- a/src/network/utils.ts +++ b/src/network/utils.ts @@ -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 diff --git a/tests/client/handlers/vaults.test.ts b/tests/client/handlers/vaults.test.ts index 93fb1efc7..e431aefd0 100644 --- a/tests/client/handlers/vaults.test.ts +++ b/tests/client/handlers/vaults.test.ts @@ -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), @@ -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-'),