Skip to content

Commit

Permalink
Fix error msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Nov 19, 2024
1 parent 0e8bb95 commit 9b07159
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/cmd/esim.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ module.exports = class eSimCommands extends CLICommandBase {
console.log(`${os.EOL}Provisioning device ${device.deviceId} with platform ${platform}`);

// Flash firmware and retrieve EID
await this._flashATPassThroughFirmware(device, platform, port);
// await this._flashATPassThroughFirmware(device, platform, port);
const eid = await this._getEid(port);
console.log(`${os.EOL}EID: ${eid}`);

await this._checkForExistingProfiles(port);
// await this._checkForExistingProfiles(port);

// Parse the JSON to get EID and profiles
const input = fs.readFileSync(this.inputJson);
Expand Down Expand Up @@ -89,6 +89,7 @@ module.exports = class eSimCommands extends CLICommandBase {
provider: profile.provider,
iccid,
time: timeTaken,
success: true,
output,
};

Expand All @@ -98,6 +99,7 @@ module.exports = class eSimCommands extends CLICommandBase {
EID: eid,
provider: profile.provider,
iccid,
success: false,
time: timeTaken,
output: err.message,
};
Expand Down Expand Up @@ -212,25 +214,20 @@ module.exports = class eSimCommands extends CLICommandBase {
async _checkForExistingProfiles(port) {
console.log(`${os.EOL}Checking for existing profiles...`);

try {
const resProfiles = await execa(this.lpa, ['listProfiles', `--serial=${port}`]);
const profilesOutput = resProfiles.stdout;

// Extract lines matching the profile format
const profilesList = profilesOutput
.split('\n')
.filter((line) => line.match(/^\d+:\[\w+,\s(?:enabled|disabled),\s?\]$/));
const resProfiles = await execa(this.lpa, ['listProfiles', `--serial=${port}`]);
const profilesOutput = resProfiles.stdout;

if (profilesList.length > 0) {
console.error(`${os.EOL}Profile(s) already exist:`, profilesList);
throw new Error('Profile(s) already exist. Device bucket is not clean.');
}
// Extract lines matching the profile format
const profilesList = profilesOutput
.split('\n')
.filter((line) => line.match(/^\d+:\[\w+,\s(?:enabled|disabled),\s?\]$/));

console.log(`${os.EOL}No existing profiles found`);
} catch (error) {
console.error(`${os.EOL}Failed to check for existing profiles: ${error.message}`);
throw error;
if (profilesList.length > 0) {
console.error(`${os.EOL}Profile(s) already exist:`, profilesList);
throw new Error('Profile(s) already exist. Troubleshoot manually.');
}

console.log(`${os.EOL}No existing profiles found`);
}

_addToJson(jsonFile, data) {
Expand Down

0 comments on commit 9b07159

Please sign in to comment.