From 0fa1e521b10f7a661c450355ec7733820ad6aac9 Mon Sep 17 00:00:00 2001 From: keeramis Date: Tue, 19 Nov 2024 13:49:13 -0800 Subject: [PATCH] Clean up --- src/cmd/esim.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/cmd/esim.js b/src/cmd/esim.js index 5f8765840..fceee2bf0 100644 --- a/src/cmd/esim.js +++ b/src/cmd/esim.js @@ -54,7 +54,7 @@ module.exports = class eSimCommands extends CLICommandBase { const profiles = eidBlock?.profiles; - console.log(`${os.EOL}Provisioning the following profiles: `); + console.log(`${os.EOL}Provisioning the following profiles to EID ${eid}:`); profiles.forEach((profile, index) => { const rspUrl = `1\$${profile.smdp}\$${profile.matching_id}`; console.log(`\t${index + 1}. ${profile.provider} (${rspUrl})`); @@ -66,11 +66,12 @@ module.exports = class eSimCommands extends CLICommandBase { console.log(`${os.EOL}${index + 1}. Downloading ${profile.provider} profile from ${rspUrl}`); const start = Date.now(); + let timeTaken = 0; let iccid = null; try { const res = await execa(this.lpa, ['download', rspUrl, `--serial=${port}`]); - const timeTaken = ((Date.now() - start) / 1000).toFixed(2); + timeTaken = ((Date.now() - start) / 1000).toFixed(2); const output = res.stdout; if (output.includes('Profile successfully downloaded')) { @@ -93,8 +94,17 @@ module.exports = class eSimCommands extends CLICommandBase { this._addToJson(this.outputJson, outputData); } catch (err) { - console.error(`${os.EOL}\tFailed to download profile: ${err.message}`); + const outputData = { + EID: eid, + provider: profile.provider, + iccid, + time: timeTaken, + output: err.message, + }; + this._addToJson(this.outputJson, outputData); + throw new Error('Failed to download profile'); } + } console.log(`${os.EOL}Provisioning complete`); @@ -239,7 +249,6 @@ module.exports = class eSimCommands extends CLICommandBase { // Write updated JSON back to the file with indentation fs.writeFileSync(jsonFile, JSON.stringify(existingJson, null, 4)); - console.log('Data appended successfully'); } catch (error) { console.error(`Failed to append data to JSON file: ${error.message}`); }