Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Code] Persist clone error messages #34977

Merged
merged 1 commit into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/plugins/code/model/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export interface WorkerProgress {
progress: number;
timestamp: Date;
revision?: string;
errorMessage?: string;
}

export interface CloneProgress {
Expand Down
13 changes: 11 additions & 2 deletions x-pack/plugins/code/public/components/admin_page/project_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
EuiProgress,
EuiText,
EuiTextColor,
EuiToolTip,
} from '@elastic/eui';
import moment from 'moment';
import React from 'react';
Expand Down Expand Up @@ -82,7 +83,14 @@ class CodeProjectItem extends React.PureComponent<{
footer = <ErrorFooter>ERROR INDEX REPO</ErrorFooter>;
hasError = true;
} else if (status.state === RepoState.CLONE_ERROR) {
footer = <ErrorFooter>ERROR CLONE REPO</ErrorFooter>;
footer = (
<ErrorFooter>
ERROR CLONE REPO&nbsp;
<EuiToolTip position="top" content={status.errorMessage}>
<EuiIcon type="iInCircle" />
</EuiToolTip>
</ErrorFooter>
);
// Disable repo link is clone failed.
disableRepoLink = true;
hasError = true;
Expand All @@ -104,7 +112,8 @@ class CodeProjectItem extends React.PureComponent<{
status &&
status.state !== RepoState.CLONING &&
status.state !== RepoState.DELETING &&
status.state !== RepoState.INDEXING;
status.state !== RepoState.INDEXING &&
status.state !== RepoState.CLONE_ERROR;
const indexVisibility = indexShow ? 'visible' : 'hidden';

const deleteShow = status && status.state !== RepoState.DELETING;
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/code/public/reducers/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface RepoStatus {
cloneProgress?: any;
timestamp?: Date;
state?: RepoState;
errorMessage?: string;
}

export interface StatusState {
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/code/server/indexer/schema/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ export const DocumentSchema = {
revision: {
type: 'keyword',
},
errorMessage: {
type: 'text',
},
cloneProgress: {
properties: {
isCloned: {
Expand Down
12 changes: 9 additions & 3 deletions x-pack/plugins/code/server/queue/abstract_git_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,26 @@ export abstract class AbstractGitWorker extends AbstractWorker {
}
}

public async updateProgress(job: Job, progress: number, cloneProgress?: CloneProgress) {
public async updateProgress(
job: Job,
progress: number,
error?: Error,
cloneProgress?: CloneProgress
) {
const { uri } = job.payload;
const p: CloneWorkerProgress = {
uri,
progress,
timestamp: new Date(),
cloneProgress,
errorMessage: error ? error.message : undefined,
};
try {
return await this.objectClient.updateRepositoryGitStatus(uri, p);
} catch (error) {
} catch (err) {
// This is a warning since it's not blocking anything.
this.log.warn(`Update git clone progress error.`);
this.log.warn(error);
this.log.warn(err);
}
}
}
6 changes: 3 additions & 3 deletions x-pack/plugins/code/server/queue/abstract_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export abstract class AbstractWorker implements Worker {
res.job
)} seconds.`
);
return await this.updateProgress(res.job, WorkerReservedProgress.ERROR);
return await this.updateProgress(res.job, WorkerReservedProgress.ERROR, res.error);
}

public async onJobTimeOut(res: any) {
Expand All @@ -130,10 +130,10 @@ export abstract class AbstractWorker implements Worker {
res.job
)} seconds.`
);
return await this.updateProgress(res.job, WorkerReservedProgress.TIMEOUT);
return await this.updateProgress(res.job, WorkerReservedProgress.TIMEOUT, res.error);
}

public async updateProgress(job: Job, progress: number) {
public async updateProgress(job: Job, progress: number, error?: Error) {
// This is an abstract class. Do nothing here. You should override this.
return new Promise<WorkerResult>((resolve, _) => {
resolve();
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/code/server/queue/clone_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class CloneWorker extends AbstractGitWorker {
const repo = RepositoryUtils.buildRepository(url);
return await repoService.clone(repo, (progress: number, cloneProgress?: CloneProgress) => {
job.payload.uri = repo.uri;
this.updateProgress(job, progress, cloneProgress);
this.updateProgress(job, progress, undefined, cloneProgress);
});
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/code/server/repository_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class RepositoryService {
const msg = `Clone repository from ${repo.url} error.`;
this.log.error(msg);
this.log.error(error);
throw new Error(msg);
throw new Error(error.message);
}
}
}
Expand Down