Skip to content

Commit 7c1efe6

Browse files
committed
Display better error messages when log and exec requests fail
1 parent 86ecbca commit 7c1efe6

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

docs/kubebox.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,9 +2575,20 @@ class Dashboard {
25752575

25762576
until(promise)
25772577
.spin(s => exec.setLabel(`${s} ${namespace}/${name}/${container}`))
2578+
.catch(error => {
2579+
exec.setLabel(`${namespace}/${name}/${container}`);
2580+
exec.terminal.write(`\x1b[31m${error}\x1b[m\r\n`);
2581+
exec.terminal.write('Type Ctrl-C to close\r\n');
2582+
exec.terminal.once('key C-c', () => {
2583+
exec.terminal.dispose();
2584+
navbar.remove(byId);
2585+
});
2586+
return Promise.reject();
2587+
})
25782588
.then(() => debug.log(`{grey-fg}Remote shell into '${namespace}/${name}/${container}'{/grey-fg}`))
25792589
.then(() => exec.setLabel(`${namespace}/${name}/${container}`))
25802590
.then(() => {
2591+
// TODO: add retry on timeout
25812592
const { promise, cancellation } = get(client.watch_pod(namespace, name, pod.metadata.resourceVersion), { generator: function* () {
25822593
let change;
25832594
while (change = yield) {
@@ -2600,8 +2611,9 @@ class Dashboard {
26002611
cancellations.add(watch, cancellation);
26012612
return promise;
26022613
})
2603-
// TODO: display error details in terminal
2604-
.catch(error => console.error(error.stack));
2614+
.catch(error => {
2615+
if (error) console.error(error.stack);
2616+
});
26052617
});
26062618

26072619
pods_table.on('select', (item, i) => {
@@ -2705,12 +2717,19 @@ class Dashboard {
27052717
until(logs.promise)
27062718
.spin(s => pod_log.setLabel(`${s} Logs {grey-fg}[${container.name}]{/grey-fg}`))
27072719
.cancel(c => cancellations.add('dashboard.pod.logs', c))
2720+
.catch(error => {
2721+
pod_log.setLabel(`Logs {grey-fg}[${container.name}]{/grey-fg}`);
2722+
pod_log.log(`\x1b[31mError: ${error.message}\x1b[m`);
2723+
return Promise.reject();
2724+
})
27082725
.then(() => debug.log(`{grey-fg}Following log for ${name}/${container.name} ...{/grey-fg}`))
27092726
.then(() => k8s.isPodTerminating(getPodByUid(pod.metadata.uid))
27102727
? pod_log.setLabel(`Logs {grey-fg}[${container.name}]{/grey-fg} {red-fg}TERMINATING{/red-fg}`)
27112728
: pod_log.setLabel(`Logs {grey-fg}[${container.name}]{/grey-fg}`))
27122729
.then(() => screen.render())
2713-
.catch(error => console.error(error.stack));
2730+
.catch(error => {
2731+
if (error) console.error(error.stack);
2732+
});
27142733

27152734
const stats = updateStatsFromCAdvisor(pod, container);
27162735
cancellations.add('dashboard.pod.stats', stats.cancellation);
@@ -3050,6 +3069,7 @@ class Exec extends Duplex {
30503069
}
30513070
},
30523071
});
3072+
this.terminal = terminal;
30533073

30543074
const browserCopyToClipboard = function (event) {
30553075
if (terminal.hasSelection()) {

lib/ui/dashboard.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,20 @@ class Dashboard {
183183

184184
until(promise)
185185
.spin(s => exec.setLabel(`${s} ${namespace}/${name}/${container}`))
186+
.catch(error => {
187+
exec.setLabel(`${namespace}/${name}/${container}`);
188+
exec.terminal.write(`\x1b[31m${error}\x1b[m\r\n`);
189+
exec.terminal.write('Type Ctrl-C to close\r\n');
190+
exec.terminal.once('key C-c', () => {
191+
exec.terminal.dispose();
192+
navbar.remove(byId);
193+
});
194+
return Promise.reject();
195+
})
186196
.then(() => debug.log(`{grey-fg}Remote shell into '${namespace}/${name}/${container}'{/grey-fg}`))
187197
.then(() => exec.setLabel(`${namespace}/${name}/${container}`))
188198
.then(() => {
199+
// TODO: add retry on timeout
189200
const { promise, cancellation } = get(client.watch_pod(namespace, name, pod.metadata.resourceVersion), { generator: function* () {
190201
let change;
191202
while (change = yield) {
@@ -208,8 +219,9 @@ class Dashboard {
208219
cancellations.add(watch, cancellation);
209220
return promise;
210221
})
211-
// TODO: display error details in terminal
212-
.catch(error => console.error(error.stack));
222+
.catch(error => {
223+
if (error) console.error(error.stack);
224+
});
213225
});
214226

215227
pods_table.on('select', (item, i) => {
@@ -313,12 +325,19 @@ class Dashboard {
313325
until(logs.promise)
314326
.spin(s => pod_log.setLabel(`${s} Logs {grey-fg}[${container.name}]{/grey-fg}`))
315327
.cancel(c => cancellations.add('dashboard.pod.logs', c))
328+
.catch(error => {
329+
pod_log.setLabel(`Logs {grey-fg}[${container.name}]{/grey-fg}`);
330+
pod_log.log(`\x1b[31mError: ${error.message}\x1b[m`);
331+
return Promise.reject();
332+
})
316333
.then(() => debug.log(`{grey-fg}Following log for ${name}/${container.name} ...{/grey-fg}`))
317334
.then(() => k8s.isPodTerminating(getPodByUid(pod.metadata.uid))
318335
? pod_log.setLabel(`Logs {grey-fg}[${container.name}]{/grey-fg} {red-fg}TERMINATING{/red-fg}`)
319336
: pod_log.setLabel(`Logs {grey-fg}[${container.name}]{/grey-fg}`))
320337
.then(() => screen.render())
321-
.catch(error => console.error(error.stack));
338+
.catch(error => {
339+
if (error) console.error(error.stack);
340+
});
322341

323342
const stats = updateStatsFromCAdvisor(pod, container);
324343
cancellations.add('dashboard.pod.stats', stats.cancellation);

lib/ui/exec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Exec extends Duplex {
4646
}
4747
},
4848
});
49+
this.terminal = terminal;
4950

5051
const browserCopyToClipboard = function (event) {
5152
if (terminal.hasSelection()) {

0 commit comments

Comments
 (0)