提交 eff8d2f8 编写于 作者: T Tomas Vik

feat: side panel error reporting

Side panel logic is now enclosed with try/catch and the new error
reporting is used to capture and log the error.
上级 4a20505f
const vscode = require('vscode');
const moment = require('moment');
const gitLabService = require('../gitlab_service');
const { SidebarTreeItem } = require('../sidebar_tree_item');
const { SidebarTreeItem } = require('./sidebar_tree_item');
const ErrorItem = require('./error_item');
class DataProvider {
constructor() {
......@@ -17,23 +18,10 @@ class DataProvider {
this.mr = null;
}
async fetchProject(workspaceFolder) {
try {
this.project = await gitLabService.fetchCurrentProject(workspaceFolder);
} catch (e) {
vscode.gitLabWorkflow.log(e.detail);
this.project = null;
this.children.push(
new SidebarTreeItem('No pipeline found.'),
new SidebarTreeItem('No merge request found.'),
new SidebarTreeItem('No closing issue found.'),
);
}
}
async fetchPipeline(workspaceFolder) {
let message = 'No pipeline found.';
let url = null;
// TODO project is always present (we throw if we fail to fetch it)
if (this.project) {
const pipeline = await gitLabService.fetchLastPipelineForCurrentBranch(workspaceFolder);
......@@ -61,6 +49,7 @@ class DataProvider {
this.mr = null;
let message = 'No merge request found.';
// TODO project is always present (we throw if we fail to fetch it)
if (this.project) {
const mr = await gitLabService.fetchOpenMergeRequestForCurrentBranch(workspaceFolder);
......@@ -75,6 +64,7 @@ class DataProvider {
}
async fetchClosingIssue(workspaceFolder) {
// TODO project is always present (we throw if we fail to fetch it)
if (this.project) {
if (this.mr) {
const issues = await gitLabService.fetchMRIssues(this.mr.iid, workspaceFolder);
......@@ -103,11 +93,16 @@ class DataProvider {
}
async getChildren() {
const workspaceFolder = await gitLabService.getCurrenWorkspaceFolder();
await this.fetchProject(workspaceFolder);
await this.fetchPipeline(workspaceFolder);
await this.fetchMR(workspaceFolder);
await this.fetchClosingIssue(workspaceFolder);
try {
const workspaceFolder = await gitLabService.getCurrenWorkspaceFolder();
this.project = await gitLabService.fetchCurrentProject(workspaceFolder);
await this.fetchPipeline(workspaceFolder);
await this.fetchMR(workspaceFolder);
await this.fetchClosingIssue(workspaceFolder);
} catch (e) {
vscode.gitLabWorkflow.handleError(e);
this.children.push(new ErrorItem());
}
return this.children;
}
......
const { TreeItem, ThemeIcon } = require('vscode');
class ErrorItem extends TreeItem {
constructor(message = 'Error occurred, please try to refresh.') {
super(message);
this.iconPath = new ThemeIcon('error');
}
}
module.exports = ErrorItem;
const vscode = require('vscode');
const gitLabService = require('../gitlab_service');
const { SidebarTreeItem } = require('../sidebar_tree_item');
const { SidebarTreeItem } = require('./sidebar_tree_item');
const ErrorItem = require('./error_item');
class DataProvider {
constructor() {
......@@ -44,10 +45,20 @@ class DataProvider {
}
async getChildren(el) {
let items = [];
try {
return await this.collectIssuables(el);
} catch (e) {
vscode.gitLabWorkflow.handleError(e);
return [new ErrorItem()];
}
}
async collectIssuables(el) {
const { customQueries } = vscode.workspace.getConfiguration('gitlab');
const projects = await gitLabService.getAllGitlabProjects();
let items = [];
if (el) {
if (el.contextValue && el.contextValue.startsWith('custom-query-')) {
const customQuery = el.contextValue.split('custom-query-')[1];
......
......@@ -14,18 +14,21 @@ const CurrentBranchDataProvider = require('./data_providers/current_branch').Dat
vscode.gitLabWorkflow = {
sidebarDataProviders: [],
log: () => {},
logError: e => vscode.gitLabWorkflow.log(e.details || `${e.message}\n${e.stack}`),
handleError: async e => {
vscode.gitLabWorkflow.logError(e);
const choice = await vscode.window.showErrorMessage(e.message, null, 'Show logs');
if (choice === 'Show logs') {
await vscode.commands.executeCommand('gl.showOutput');
}
},
};
const wrapWithCatch = command => async () => {
try {
await command();
} catch (e) {
vscode.gitLabWorkflow.log(e.details || `${e.message}\n${e.stack}`);
const choice = await vscode.window.showErrorMessage(e.message, null, 'Show logs');
if (choice === 'Show logs') {
vscode.commands.executeCommand('gl.showOutput');
}
await vscode.gitLabWorkflow.handleError(e);
}
};
......
......@@ -156,9 +156,9 @@ async function fetchCurrentProject(workspaceFolder) {
async function fetchCurrentProjectSwallowError(workspaceFolder) {
try {
return fetchCurrentProject(workspaceFolder);
return await fetchCurrentProject(workspaceFolder);
} catch (error) {
vscode.gitLabWorkflow.log(error.detail);
vscode.gitLabWorkflow.logError(error);
return null;
}
}
......@@ -213,13 +213,13 @@ async function getAllGitlabProjects() {
let workspaceFolders = [];
if (vscode.workspace.workspaceFolders) {
workspaceFolders = vscode.workspace.workspaceFolders.map(workspaceFolder => ({
label: fetchCurrentProjectSwallowError(workspaceFolder.uri.fsPath),
label: fetchCurrentProject(workspaceFolder.uri.fsPath),
uri: workspaceFolder.uri.fsPath,
}));
const labels = await Promise.all(workspaceFolders.map(workspaceFolder => workspaceFolder.label))
.then(res => res)
.catch(err => console.log(err));
const labels = await Promise.all(
workspaceFolders.map(workspaceFolder => workspaceFolder.label),
);
// Temporarily disable eslint to be able to start enforcing stricter rules
// eslint-disable-next-line no-plusplus
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册