@@ -181,11 +181,6 @@ window.addEventListener('popstate', parseURL);
181181// --- Core Logic ---
182182
183183function parseURL ( ) {
184- // Skip URL parsing if we're on the 404 page
185- if ( document . querySelector ( '.error-container' ) ) {
186- return ;
187- }
188-
189184 // Skip URL parsing for specific pages we want to preserve
190185 const specialPages = [ '/featured-repos' , '/featured-repos.html' ] ;
191186 if ( specialPages . includes ( window . location . pathname ) ) {
@@ -240,9 +235,19 @@ function parseURL() {
240235 fetchRepoTree ( ) ; // This will handle metadata update after fetch
241236 }
242237 }
238+ } else if ( window . location . pathname . match ( / \/ r e p o \/ .* $ / ) ) {
239+ // Handle invalid repo URL format but keep user on the current page
240+ // This is for URLs like /repo/something-invalid/
241+ if ( errorContainer ) {
242+ showError ( "Invalid repository URL format. Please use the format: /repo/username/repository/branch/" ) ;
243+ // Ensure tree is cleared
244+ clearTree ( ) ;
245+ // Clear URL but stay on current page
246+ history . replaceState ( { } , document . title , "/" ) ;
247+ }
243248 } else {
244249 // Only reset to homepage if we're actually on the homepage
245- // This prevents overriding metadata for other pages like /repo-pages/
250+ // This prevents overriding metadata for other pages
246251 if ( window . location . pathname === '/' || window . location . pathname === '/index.html' ) {
247252 updateMetaData (
248253 'GitHub repo explorer: visualize and navigate github project structures' , // Default Title
@@ -792,8 +797,68 @@ function showError(message, append = false) {
792797 appendMsg . style . marginTop = '0.5em' ;
793798 errorContainer . appendChild ( appendMsg ) ;
794799 } else {
795- // Replace existing error content
796- errorContainer . innerHTML = message ; // Use innerHTML to allow basic formatting like <i>
800+ // Replace existing error content with enhanced error display
801+ let errorHTML = `<div class="error-message"><i class="fas fa-exclamation-circle"></i> ${ message } </div>` ;
802+
803+ // Add suggestions for common repository errors
804+ if ( message . includes ( "not found" ) || message . includes ( "404" ) ) {
805+ // Get example repositories from the featured repos if available or use fallbacks
806+ let repoSuggestions = '' ;
807+ // Try to get first 3 repositories from the featured-repos page if loaded
808+ const repoEntries = document . querySelectorAll ( '.repo-entry' ) ;
809+ if ( repoEntries && repoEntries . length > 0 ) {
810+ const suggestions = [ ] ;
811+ for ( let i = 0 ; i < Math . min ( repoEntries . length , 3 ) ; i ++ ) {
812+ const entry = repoEntries [ i ] ;
813+ const repoName = entry . getAttribute ( 'data-repo' ) ;
814+ const branch = entry . querySelector ( 'small' ) ?
815+ entry . querySelector ( 'small' ) . textContent . replace ( / [ ( ) ] / g, '' ) : 'main' ;
816+ if ( repoName ) {
817+ suggestions . push ( `<a href="/repo/${ repoName } /${ branch } /">${ repoName } </a>` ) ;
818+ }
819+ if ( suggestions . length >= 3 ) break ;
820+ }
821+ repoSuggestions = suggestions . join ( '' ) ;
822+ }
823+
824+ // If no repo entries found, use hardcoded examples
825+ if ( ! repoSuggestions ) {
826+ repoSuggestions = `
827+ <a href="/repo/mgks/GitHubTree/main/">mgks/GitHubTree</a>
828+ <a href="/repo/facebook/react/main/">facebook/react</a>
829+ <a href="/repo/tensorflow/tensorflow/main/">tensorflow/tensorflow</a>
830+ ` ;
831+ }
832+
833+ errorHTML += `
834+ <div class="error-suggestions">
835+ <h3>Suggestions:</h3>
836+ <ul>
837+ <li>Check that the repository exists and is public</li>
838+ <li>Verify the repository name and username are spelled correctly</li>
839+ <li>Try exploring one of these popular repositories instead:</li>
840+ </ul>
841+ <div class="suggestion-examples">
842+ ${ repoSuggestions }
843+ </div>
844+ </div>
845+ ` ;
846+ } else if ( message . includes ( "branch" ) ) {
847+ errorHTML += `
848+ <div class="error-suggestions">
849+ <h3>Suggestions:</h3>
850+ <ul>
851+ <li>Check that the branch exists in the repository</li>
852+ <li>Try using the default branch (usually 'main' or 'master')</li>
853+ <li>Verify the branch name is spelled correctly</li>
854+ </ul>
855+ </div>
856+ ` ;
857+ } else if ( message . includes ( "rate limit" ) ) {
858+ // Rate limit error suggestions already handled by handleRateLimit function
859+ }
860+
861+ errorContainer . innerHTML = errorHTML ; // Use innerHTML to allow basic formatting
797862 }
798863 errorContainer . style . display = 'block' ;
799864}
0 commit comments