Skip to content

Commit fc91a71

Browse files
authored
fix: integration silent errors (#197)
The cli’s for the integration packages could silently error. The logic is wrapped in an immediately invoked function expression. The function is async, and if there is an error this results in an unhandled promise rejection. Catch the error, log, and exit with a non-zero code. I also cleaned up some of the path expressions, and removed the ts-ignore.
1 parent 82346ed commit fc91a71

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

modules/integration-browser/src/build_decrypt_fixtures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { DecryptManifestList } from './types' // eslint-disable-line no-unused-v
2727
* 1. The code is not tied to a specific copy of the manifest information
2828
* 2. The tests can be run on a subset of tests for debugging.
2929
*/
30-
export async function buildDecryptFixtures (fixtures: string, vectorFile: string, testName: string, slice: string) {
30+
export async function buildDecryptFixtures (fixtures: string, vectorFile: string, testName?: string, slice?: string) {
3131
const [start = 0, end = 9999] = (slice || '').split(':').map(n => parseInt(n, 10))
3232

3333
const centralDirectory = await Open.file(vectorFile)

modules/integration-browser/src/build_encrypt_fixtures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import got from 'got'
3434
* 1. The code is not tied to a specific copy of the manifest information
3535
* 2. The tests can be run on a subset of tests for debugging.
3636
*/
37-
export async function buildEncryptFixtures (fixtures: string, manifestFile: string, keyFile: string, testName: string, slice: string) {
37+
export async function buildEncryptFixtures (fixtures: string, manifestFile: string, keyFile: string, testName?: string, slice?: string) {
3838
const [start = 0, end = 9999] = (slice || '').split(':').map(n => parseInt(n, 10))
3939
const { tests, plaintexts }: EncryptManifestList = await getParsedJSON(manifestFile)
4040
const { keys }: KeyList = await getParsedJSON(keyFile)

modules/integration-browser/src/cli.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,22 @@ if (!existsSync(fixtures)) {
7373
}
7474

7575
;(async (argv) => {
76-
const { _: [ command ], testName, slice, karma, decryptOracle = '' } = argv
76+
const { _: [ command ], testName, slice, karma } = argv
7777

7878
writeFileSync(`${fixtures}/decrypt_tests.json`, JSON.stringify([]))
7979
writeFileSync(`${fixtures}/encrypt_tests.json`, JSON.stringify([]))
80-
writeFileSync(`${fixtures}/decrypt_oracle.json`, JSON.stringify(decryptOracle))
8180

8281
if (command === 'decrypt') {
83-
const { vectorFile } = argv
84-
const vectorPath = join(__dirname, vectorFile as string)
85-
if (!existsSync(vectorPath)) throw new Error(`No file found at ${vectorPath}`)
86-
// @ts-ignore
87-
await buildDecryptFixtures(fixtures, vectorFile, testName, slice)
82+
// It is not clear how to get yargs/typescript to play nicely with sub commands
83+
const { vectorFile } = argv as unknown as { vectorFile: string}
84+
if (!existsSync(vectorFile)) throw new Error(`No file found at ${vectorFile}`)
85+
await buildDecryptFixtures(fixtures, vectorFile as string, testName, slice)
8886
} else if (command === 'encrypt') {
89-
const { manifestFile, keyFile } = argv
90-
// @ts-ignore
91-
await buildEncryptFixtures(fixtures, manifestFile, keyFile, testName, slice)
87+
// It is not clear how to get yargs/typescript to play nicely with sub commands
88+
const { manifestFile, keyFile, decryptOracle } = argv as unknown as { manifestFile: string, keyFile: string, decryptOracle: string}
89+
writeFileSync(`${fixtures}/decrypt_oracle.json`, JSON.stringify(decryptOracle))
90+
91+
await buildEncryptFixtures(fixtures, manifestFile as string, keyFile as string, testName, slice)
9292
} else {
9393
console.log(`Unknown command ${command}`)
9494
cli.showHelp()
@@ -101,3 +101,7 @@ if (!existsSync(fixtures)) {
101101
})
102102
}
103103
})(cli.argv)
104+
.catch(err => {
105+
console.log(err)
106+
process.exit(1)
107+
})

modules/integration-node/src/cli.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,10 @@ const cli = yargs
6464
/* I set the result to 1 so that if I fall through the exit condition is a failure */
6565
let result = 1
6666
if (command === 'decrypt') {
67-
const { vectorFile } = argv
68-
// @ts-ignore
67+
const { vectorFile } = argv as unknown as { vectorFile: string}
6968
result = await integrationDecryptTestVectors(vectorFile, tolerateFailures, testName)
7069
} else if (command === 'encrypt') {
71-
const { manifestFile, keyFile, decryptOracle } = argv
72-
// @ts-ignore
70+
const { manifestFile, keyFile, decryptOracle } = argv as unknown as { manifestFile: string, keyFile: string, decryptOracle: string}
7371
result = await integrationEncryptTestVectors(manifestFile, keyFile, decryptOracle, tolerateFailures, testName)
7472
} else {
7573
console.log(`Unknown command ${command}`)
@@ -78,3 +76,7 @@ const cli = yargs
7876

7977
if (result) process.exit(result)
8078
})(cli.argv)
79+
.catch(err => {
80+
console.log(err)
81+
process.exit(1)
82+
})

0 commit comments

Comments
 (0)