import { Errors as GitErrors } from 'isomorphic-git'; import { X, ArrowDown, ArrowUp } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { Link } from 'react-router-dom'; import { getSentryInstance } from '@/lib/sentry'; interface SyncStepErrorProps { error: Error; onDismiss: () => void; onForcePull: () => void; onForcePush: () => void; onPull: () => void; remoteUrl: URL; remoteName: string; } export function SyncStepError({ error, onDismiss, onForcePull, onForcePush, onPull, remoteName, remoteUrl }: SyncStepErrorProps) { const renderForcePullButton = () => ( ); const renderForcePushButton = () => ( ); const renderPullButton = () => ( ); const renderDismissButton = () => ( ); // MergeNotSupportedError - offer force pull or force push if (error instanceof GitErrors.MergeNotSupportedError) { return (
Cannot merge changes automatically. Your local changes conflict with the remote repository. {renderDismissButton()}
{renderForcePullButton()} {renderForcePushButton()}
); } // FastForwardError - offer force pull or force push if (error instanceof GitErrors.FastForwardError) { return (
Cannot fast-forward. The remote has changes that conflict with your local commits. {renderDismissButton()}
{renderForcePullButton()} {renderForcePushButton()}
); } // PushRejectedError - remote has changes if (error instanceof GitErrors.PushRejectedError) { return (
Push rejected. The remote repository has changes you don't have locally. Try pulling first. {renderDismissButton()}
{renderPullButton()} {renderForcePushButton()}
); } // HTTP errors if (error instanceof GitErrors.HttpError) { let message: React.ReactNode = `HTTP Error: ${error.data.statusCode} ${error.data.statusMessage}`; if (remoteUrl.protocol === 'nostr:') { // This should never happen getSentryInstance()?.captureException(error); message = `There was an HTTP (${error.data.statusCode}) error communicating with Nostr Git servers.` } else if (remoteUrl.protocol !== 'http:' && remoteUrl.protocol !== 'https:') { switch (error.data.statusCode) { case 401: message = <>Your API token for {remoteName} is probably invalid or expired. Please try logging out and back into {remoteName} in Git Settings. break; case 403: message = <>You don't have permission to access this repository on {remoteName}. Try checking your permissions on {remoteName}.; break; } } return (
{message} {renderDismissButton()}
); } // Generic error fallback return (
{error.message} {renderDismissButton()}
); }