Skip to content

Commit 0dfb838

Browse files
committed
bug: working on throwing errors
[ci skip]
1 parent 378aa45 commit 0dfb838

5 files changed

Lines changed: 33 additions & 22 deletions

File tree

src/client/handlers/VaultsSecretsGet.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,23 @@ class VaultsSecretsGet extends RawHandler<{
7575
throw new vaultsErrors.ErrorVaultsVaultUndefined();
7676
}
7777
// Get secret contents
78-
yield* vaultManager.withVaultsG([vaultId], (vault) => {
79-
return vault.readG(async function* (fs): AsyncGenerator<
80-
Uint8Array,
81-
void,
82-
void
83-
> {
84-
const contents = fileTree.serializerStreamFactory(fs, secretNames);
85-
try {
78+
yield* vaultManager.withVaultsG(
79+
[vaultId],
80+
(vault) => {
81+
return vault.readG(async function* (fs): AsyncGenerator<
82+
Uint8Array,
83+
void,
84+
void
85+
> {
86+
const contents = fileTree.serializerStreamFactory(
87+
fs,
88+
secretNames,
89+
);
8690
for await (const chunk of contents) yield chunk;
87-
} catch (e) {
88-
if (e.name === 'ErrorSecretsSecretUndefined') {
89-
throw new vaultsErrors.ErrorSecretsSecretUndefined(e.message, {
90-
cause: e.cause,
91-
});
92-
}
93-
throw e;
94-
}
95-
});
96-
});
91+
});
92+
},
93+
tran,
94+
);
9795
},
9896
);
9997

src/utils/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,13 @@ function asyncGeneratorToStream<T>(
560560
if (done) controller.close();
561561
else controller.enqueue(value);
562562
} catch (e) {
563+
console.error('from generator: ', e)
563564
controller.error(e);
564565
}
565566
},
567+
cancel: async (reason) => {
568+
await generator.throw(reason).catch(() => {});
569+
},
566570
});
567571
}
568572

src/vaults/VaultInternal.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,11 @@ class VaultInternal {
433433
): AsyncGenerator<T, TReturn, TNext> {
434434
const efsVault = this.efsVault;
435435
return withG([this.lock.read()], async function* () {
436-
return yield* g(efsVault);
436+
try {
437+
return yield* g(efsVault);
438+
} catch (e) {
439+
throw e;
440+
}
437441
});
438442
}
439443

src/vaults/VaultManager.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,9 +1046,13 @@ class VaultManager {
10461046
tran?: DBTransaction,
10471047
): AsyncGenerator<T, Treturn, Tnext> {
10481048
if (tran == null) {
1049-
return yield* this.db.withTransactionG((tran) =>
1050-
this.withVaultsG(vaultIds, g, tran),
1051-
);
1049+
try {
1050+
return yield* this.db.withTransactionG((tran) =>
1051+
this.withVaultsG(vaultIds, g, tran),
1052+
);
1053+
} catch (e) {
1054+
throw e;
1055+
}
10521056
}
10531057

10541058
// Obtaining locks

tests/utils/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const expectRemoteError = async <T>(
1717
try {
1818
return await promise;
1919
} catch (e) {
20+
console.error(e.cause);
2021
expect(e.cause).toBeInstanceOf(error);
2122
}
2223
};

0 commit comments

Comments
 (0)