Files
buzz/desktop/src/features/projects/lib/projectGitError.ts
Thomas Petersen 9ae5e5cd61 feat(desktop): refine repository-aware project workspaces
Make Projects repository-aware across navigation, source management, work items, discussions, and contextual actions while consolidating detail views into consistent single-column workspaces.

Signed-off-by: Thomas Petersen <thomasp@squareup.com>
2026-08-15 21:07:00 -04:00

83 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { ProjectRepoUnavailableReason } from "./projectRepoAvailability";
export type ProjectGitErrorPresentation = {
title: string;
description: string;
};
function errorText(error: unknown) {
if (error instanceof Error) return error.message.toLowerCase();
return typeof error === "string" ? error.toLowerCase() : "";
}
function isGitHubUrl(cloneUrl: string | null | undefined) {
try {
return new URL(cloneUrl ?? "").hostname.toLowerCase() === "github.com";
} catch {
return false;
}
}
export function projectCloneErrorPresentation(
error: unknown,
cloneUrl?: string | null,
unavailableReason?: ProjectRepoUnavailableReason,
): ProjectGitErrorPresentation {
const message = errorText(error);
const github = isGitHubUrl(cloneUrl);
if (unavailableReason === "access") {
return {
title: "Repository access restricted",
description:
"You need access to the repository’s channel before you can clone it.",
};
}
if (
/\b(?:401|403)\b|authenticat|authoriz|permission denied|access denied|ssh certificate/.test(
message,
)
) {
return {
title: "Repository access required",
description: github
? "This repository requires GitHub authentication. Buzz currently clones public GitHub repositories without credentials."
: "Buzz could not authenticate with this repository. Check your access and try again.",
};
}
if (/\b404\b|repository not found|repository does not exist/.test(message)) {
return {
title: "Repository not found",
description:
"Check that the repository link is correct and that the repository still exists.",
};
}
if (
/timed? out|could not resolve host|failed to connect|connection (?:refused|reset)|network is unreachable|offline/.test(
message,
)
) {
return {
title: "Couldn’t reach the repository",
description: "Check your connection and try cloning again.",
};
}
if (
/already exists and is not an empty directory|destination path .* exists/.test(
message,
)
) {
return {
title: "Local folder already exists",
description:
"Choose a different repositories directory or remove the existing checkout.",
};
}
return {
title: "Couldn’t clone repository",
description: github
? "Try again, or open the repository on GitHub for more information."
: "Try again. If the problem continues, contact the repository owner.",
};
}