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

Fix/improved-git-sync-errors #6446

Merged
merged 4 commits into from
Sep 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const TabPill = styled.div({
export const GitRepositoryCloneModal = (props: ModalProps) => {
const { organizationId, projectId } = useParams() as { organizationId: string; projectId: string };
const modalRef = useRef<ModalHandle>(null);
const updateGitRepositoryFetcher = useFetcher();
const cloneGitRepositoryFetcher = useFetcher();

const [selectedTab, setTab] = useState<OauthProviderName>('github');

Expand All @@ -46,7 +46,7 @@ export const GitRepositoryCloneModal = (props: ModalProps) => {
...repoPatch
} = gitRepositoryPatch;

updateGitRepositoryFetcher.submit(
cloneGitRepositoryFetcher.submit(
{
...repoPatch,
authorName: author?.name || '',
Expand All @@ -60,14 +60,15 @@ export const GitRepositoryCloneModal = (props: ModalProps) => {
);
};

const isSubmitting = updateGitRepositoryFetcher.state === 'submitting';
const errors = updateGitRepositoryFetcher.data?.errors as (Error | string)[];

const isSubmitting = cloneGitRepositoryFetcher.state === 'submitting';
const errors = cloneGitRepositoryFetcher.data?.errors as (Error | string)[];
useEffect(() => {
if (errors && errors.length) {
const errorMessage = errors.map(e => e instanceof Error ? e.message : typeof e === 'string' && e).join(', ');

showAlert({
title: 'Error Cloning Repository',
message: errors.map(e => e instanceof Error ? e.message : typeof e === 'string' && e).join(''),
message: errorMessage,
});
}
}, [errors]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ export const GitRepositorySettingsModal = (props: ModalProps & {

useEffect(() => {
if (errors && errors.length) {
const errorMessage = errors.map(e => e instanceof Error ? e.message : typeof e === 'string' && e).join(', ');

showAlert({
title: 'Error Cloning Repository',
message: errors.map(e => e instanceof Error ? e.message : typeof e === 'string' && e).join(''),
message: errorMessage,
});
}
}, [errors]);
Expand Down
71 changes: 39 additions & 32 deletions packages/insomnia/src/ui/routes/git-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export const gitRepoAction: ActionFunction = async ({
gitRepository: gitRepository,
};
} catch (e) {
console.error(e);
const errorMessage =
e instanceof Error ? e.message : 'Error while fetching git repository.';
return {
Expand Down Expand Up @@ -410,50 +411,27 @@ export const cloneGitRepoAction: ActionFunction = async ({
properties: vcsSegmentEventProperties('git', 'clone'),
});
repoSettingsPatch.needsFullClone = true;
let fsClient = MemClient.createClient();
repoSettingsPatch.uri = addDotGit(repoSettingsPatch.uri);
const fsClient = MemClient.createClient();

const providerName = getOauth2FormatName(repoSettingsPatch.credentials);
try {
await shallowClone({
fsClient,
gitRepository: repoSettingsPatch as GitRepository,
});
} catch (originalUriError) {
if (repoSettingsPatch.uri.endsWith('.git')) {
window.main.trackSegmentEvent({
event: SegmentEvent.vcsSyncComplete,
properties: {
...vcsSegmentEventProperties('git', 'clone', originalUriError.message),
providerName,
},
});
} catch (err) {
console.error(err);

if (err instanceof Errors.HttpError) {
return {
errors: [originalUriError.message],
errors: [`${err.message}, ${err.data.response}`],
};
}

const dotGitUri = addDotGit(repoSettingsPatch.uri);

try {
fsClient = MemClient.createClient();
await shallowClone({
fsClient,
gitRepository: { ...repoSettingsPatch, uri: dotGitUri } as GitRepository,
});
// by this point the clone was successful, so update with this syntax
repoSettingsPatch.uri = dotGitUri;
} catch (dotGitError) {
window.main.trackSegmentEvent({
event: SegmentEvent.vcsSyncComplete, properties: {
...vcsSegmentEventProperties('git', 'clone', dotGitError.message),
providerName,
},
});
return {
errors: [dotGitError.message],
errors: [err.message],
};
}
}

const containsInsomniaDir = async (
Expand Down Expand Up @@ -811,6 +789,11 @@ export const createNewGitBranchAction: ActionFunction = async ({
},
});
} catch (err) {
if (err instanceof Errors.HttpError) {
return {
errors: [`${err.message}, ${err.data.response}`],
};
}
const errorMessage =
err instanceof Error
? err.message
Expand Down Expand Up @@ -855,6 +838,11 @@ export const checkoutGitBranchAction: ActionFunction = async ({
try {
await GitVCS.checkout(branch);
} catch (err) {
if (err instanceof Errors.HttpError) {
return {
errors: [`${err.message}, ${err.data.response}`],
};
}
const errorMessage = err instanceof Error ? err.message : err;
return {
errors: [errorMessage],
Expand Down Expand Up @@ -928,6 +916,11 @@ export const mergeGitBranchAction: ActionFunction = async ({
},
});
} catch (err) {
if (err instanceof Errors.HttpError) {
return {
errors: [`${err.message}, ${err.data.response}`],
};
}
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
return { errors: [errorMessage] };
}
Expand Down Expand Up @@ -1013,9 +1006,14 @@ export const pushToGitRemoteAction: ActionFunction = async ({
try {
canPush = await GitVCS.canPush(gitRepository.credentials);
} catch (err) {
if (err instanceof Errors.HttpError) {
return {
errors: [`${err.message}, ${err.data.response}`],
};
}
const errorMessage = err instanceof Error ? err.message : 'Unknown Error';

return { errors: [`Error Pushing Repository ${errorMessage}`] };
return { errors: [errorMessage] };
}
// If nothing to push, display that to the user
if (!canPush) {
Expand All @@ -1035,6 +1033,11 @@ export const pushToGitRemoteAction: ActionFunction = async ({
},
});
} catch (err: unknown) {
if (err instanceof Errors.HttpError) {
return {
errors: [`${err.message}, ${err.data.response}`],
};
}
const errorMessage = err instanceof Error ? err.message : 'Unknown Error';

window.main.trackSegmentEvent({
Expand Down Expand Up @@ -1093,7 +1096,7 @@ export const pullFromGitRemoteAction: ActionFunction = async ({
credentials: gitRepository?.credentials,
});
} catch (e) {
console.warn('Error fetching from remote');
console.warn('Error fetching from remote', e);
}

try {
Expand All @@ -1105,6 +1108,9 @@ export const pullFromGitRemoteAction: ActionFunction = async ({
},
});
} catch (err: unknown) {
if (err instanceof Errors.HttpError) {
return { errors: [`${err.message}, ${err.data.response}`] };
}
const errorMessage = err instanceof Error ? err.message : 'Unknown Error';
window.main.trackSegmentEvent({
event:
Expand Down Expand Up @@ -1298,6 +1304,7 @@ export const gitStatusAction: ActionFunction = async ({
},
};
} catch (e) {
console.error(e);
return {
status: {
localChanges: 0,
Expand Down