Skip to content

Commit 040db93

Browse files
author
Tim Etchells
committed
more small changes to start behaviour
- fix uncaught promise rejection - fix inaccurate logging - ping environment until it comes up
1 parent b64a1c2 commit 040db93

3 files changed

Lines changed: 36 additions & 10 deletions

File tree

dev/src/command/ActivateConnectionCmd.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,35 @@ async function tryAddConnection(connInfo: MCUtil.IConnectionInfo): Promise<Conne
8282
try {
8383
try {
8484
envData = await MCEnvironment.getEnvData(url);
85+
Log.d("Initial connect succeeded, no need to start Codewind");
8586
}
8687
catch (err) {
8788
await InstallerWrapper.start();
88-
envData = await MCEnvironment.getEnvData(url);
89+
90+
Log.d("Codewind should have started, pinging for ENV data now...");
91+
envData = await new Promise<MCEnvironment.IMCEnvData>((resolve, reject) => {
92+
let tries = 0;
93+
const interval = setInterval(() => {
94+
tries++;
95+
96+
MCEnvironment.getEnvData(url)
97+
.then((envData_) => {
98+
// success
99+
Log.i(`Connected to codewind after ${tries} tries`);
100+
clearInterval(interval);
101+
return resolve(envData_);
102+
})
103+
.catch((_err) => {
104+
if (tries > 10) {
105+
clearInterval(interval);
106+
return reject("Codewind appeared to start, but connecting failed.");
107+
}
108+
else {
109+
Log.d("Failed to contact codewind, will try again");
110+
}
111+
});
112+
}, 500);
113+
});
89114
}
90115
}
91116
catch (err) {

dev/src/microclimate/connection/Connection.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ export default class Connection implements vscode.QuickPickItem, vscode.Disposab
105105
this.hasConnected = true;
106106
this._isConnected = true;
107107
Log.d(`${this} is now connected`);
108-
await this.forceUpdateProjectList();
108+
try {
109+
await this.forceUpdateProjectList();
110+
}
111+
catch (err) {
112+
Log.e("Error getting projects list after connect event", err)
113+
}
109114

110115
this.onChange();
111116
}

dev/src/microclimate/connection/InstallerWrapper.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ namespace InstallerWrapper {
8484
return;
8585
}
8686

87+
Log.i(`Running installer command: ${cmd}`);
88+
8789
const userMsg = getUserActionName(cmd) + "...";
8890
currentOperation = cmd;
8991

@@ -98,22 +100,16 @@ namespace InstallerWrapper {
98100
timeout: START_TIMEOUT,
99101
}, async (err, stdout, stderr) => {
100102
if (err) {
101-
Log.e("Error starting with installer", err);
103+
Log.e("Error running with installer", err);
102104
Log.e("Stdout:", stdout.toString());
103105
Log.e("Stderr:", stderr.toString());
104106
currentOperation = undefined;
105107
return reject(err);
106108
}
107-
Log.i("Successfully started CW with installer");
108-
109-
// if (cmd === InstallerCommands.START) {
110-
// // additional delay
111-
// await new Promise((resolve2) => setTimeout(resolve2, 5000));
112-
// }
109+
Log.i(`Successfully ran installer command: ${cmd}`);
113110

114111
currentOperation = undefined;
115112
resolve();
116-
Log.d("Finished starting Codewind");
117113
});
118114
});
119115
});

0 commit comments

Comments
 (0)