Skip to content

Commit

Permalink
Display error messages for invalid trace type (#231)
Browse files Browse the repository at this point in the history
fixes #187

Signed-off-by: Ankush Tyagi <ankush.tyagi@ericsson.com>
  • Loading branch information
ankusht-work authored Jan 25, 2021
1 parent ddc43d1 commit f565daf
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions viewer-prototype/src/browser/trace-viewer/trace-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ export class TraceViewerWidget extends ReactWidget {
}
}

// Check if the folder is empty.
if (tracesArray.length === 0) {
progress.report({ message: 'Complete', work: { done: 100, total: 100 } });
progress.cancel();
this.messageService.error('No valid traces found in the selected directory: ' + this.uri);
this.dispose();
return;
}

const traces = new Array<Trace>();
if (isCancelled.value) {
progress.report({ message: 'Complete', work: { done: 100, total: 100 } });
Expand All @@ -134,13 +143,16 @@ export class TraceViewerWidget extends ReactWidget {
}

progress.report({ message: 'Opening traces', work: { done: 30, total: 100 } });
const invalidTraces = new Array<string>();
for (let i = 0; i < tracesArray.length; i++) {
if (isCancelled.value) {
break;
}
const trace = await this.traceManager.openTrace(tracesArray[i].toString(), tracesArray[i].name + tracesArray[i].ext);
if (trace) {
traces.push(trace);
} else {
invalidTraces.push(tracesArray[i].name.concat(tracesArray[i].ext));
}
}

Expand All @@ -154,21 +166,30 @@ export class TraceViewerWidget extends ReactWidget {
this.dispose();
return;
}
progress.report({message: 'Merging traces', work: {done: 70, total: 100}});
const experiment = await this.experimentManager.openExperiment(this.uri.name + this.uri.ext, traces);
if (experiment) {
this.openedExperiment = experiment;
this.title.label = 'Trace: ' + experiment.name;
this.id = experiment.UUID;
progress.report({ message: 'Merging traces', work: { done: 70, total: 100 } });

if (this.isVisible) {
this.explorerWidget.onOpenedTracesWidgetActivated(experiment);
if (traces === undefined || traces.length === 0) {
// All the traces are invalid. Display the error message and exit.
this.messageService.error('Invalid trace(s): ' + invalidTraces.toString());
this.dispose();
} else {
const experiment = await this.experimentManager.openExperiment(this.uri.name + this.uri.ext, traces);
if (experiment) {
this.openedExperiment = experiment;
this.title.label = 'Trace: ' + experiment.name;
this.id = experiment.UUID;

if (this.isVisible) {
this.explorerWidget.onOpenedTracesWidgetActivated(experiment);
}
}
// Check if there are any invalid traces and display the warning message with the names of the invalid traces if any.
if (Array.isArray(invalidTraces) && invalidTraces.length) {
this.messageService.warn('Invalid trace(s): ' + invalidTraces.toString());
}
}

this.update();
} catch (e) {
console.log(e);
this.dispose();
}
progress.report({ message: 'Complete', work: { done: 100, total: 100 } });
Expand Down

0 comments on commit f565daf

Please sign in to comment.