Skip to content

Commit

Permalink
chore: cleaned up files
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Nov 7, 2024
1 parent 25d5fea commit 5a4e619
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 38 deletions.
9 changes: 8 additions & 1 deletion src/network/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,14 @@ function fromError(error: any) {
if (error instanceof Error) {
const cause = fromError(error.cause);
const timestamp: string = ((error as any).timestamp ?? new Date()).toJSON();
if (error instanceof ErrorPolykey) {
// ErrorParse is an exception to the Polykey error tree, where the error is
// not actually derived from ErrorPolykey, but rather an AbstractError. We
// cannot simply check for AbstractError because other libraries can also
// throw that, and those errors should be wrapped in ErrorPolykeyUnexpected.
if (
error instanceof ErrorPolykey ||
error instanceof validationErrors.ErrorParse
) {
return error.toJSON();
} else if (error instanceof AggregateError) {
// AggregateError has an `errors` property
Expand Down
58 changes: 21 additions & 37 deletions src/vaults/VaultOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,50 +264,34 @@ async function listSecrets(vault: Vault): Promise<string[]> {
});
}

// /**
// * Changes the contents of a secret. Creates a new file if it doesn't exist.
// */
// async function writeSecret(
// vault: Vault,
// secretName: string,
// content: Buffer | string,
// logger?: Logger,
// ): Promise<void> {
// await vault.writeF(async (efs) => {
// try {
// await efs.writeFile(secretName, content);
// logger?.info(`Wrote secret ${secretName} in vault ${vault.vaultId}`);
// } catch (e) {
// if (e.code === 'ENOENT') {
// throw new vaultsErrors.ErrorSecretsSecretUndefined(
// `One or more parent directories for '${secretName}' do not exist`,
// { cause: e },
// );
// }
// if (e.code === 'EISDIR') {
// throw new vaultsErrors.ErrorSecretsIsDirectory(
// `Secret path '${secretName}' is a directory`,
// { cause: e },
// );
// }
// throw e;
// }
// });
// }

/**
* Changes the contents of a secret. Creates a new file if it doesn't exist.
*/
async function writeSecret(
vault: Vault,
secretName: string,
content: Buffer | string,
logger?: Logger,
): Promise<void> {
console.log(Object.create(null))
throw Object.create(null);
throw new Error('oh no')
throw 123;
await vault.writeF(async (efs) => {
await efs.writeFile(secretName, content);
logger?.info(`Wrote secret ${secretName} in vault ${vault.vaultId}`);
try {
await efs.writeFile(secretName, content);
logger?.info(`Wrote secret ${secretName} in vault ${vault.vaultId}`);
} catch (e) {
if (e.code === 'ENOENT') {
throw new vaultsErrors.ErrorSecretsSecretUndefined(
`One or more parent directories for '${secretName}' do not exist`,
{ cause: e },
);
}
if (e.code === 'EISDIR') {
throw new vaultsErrors.ErrorSecretsIsDirectory(
`Secret path '${secretName}' is a directory`,
{ cause: e },
);
}
throw e;
}
});
}

Expand Down

0 comments on commit 5a4e619

Please sign in to comment.