fix: improve sync error messages to distinguish bad URLs from incompatible repo structures#33
Conversation
…tible repo structures
WalkthroughThe changes enhance sync error handling by introducing URL validation in the sync manager and restructuring error messages to categorize failures by type (invalid URLs, incompatible structures). Notifications now display categorized failure counts with detailed per-repository reasons. Changes
Sequence DiagramsequenceDiagram
participant SyncProcess as Sync Process
participant Manager as SyncManager
participant Validate as validateRepositoryUrl()
participant Results as Error Results
participant Notifications as Notifications
SyncProcess->>Manager: Start repository sync
Manager->>Validate: Validate repository URL
alt URL Valid
Validate-->>Manager: undefined (valid)
Manager->>Manager: Proceed with sync checks
else URL Invalid
Validate-->>Manager: error string
Manager->>Results: Record URL validation error
Manager->>Manager: Skip repository
end
Manager->>Manager: Check for relevant files
alt No Relevant Files Found
Manager->>Manager: Compute enabled types & structure error
Manager->>Results: Record structure error
end
SyncProcess->>Notifications: Format failure message
Notifications->>Results: Read categorized errors
Notifications->>Notifications: Count invalid URLs, incompatible structures, other
Notifications-->>SyncProcess: Return categorized failure summary
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can enable review details to help with troubleshooting, context usage and more.Enable the |
There was a problem hiding this comment.
Pull request overview
Improves sync error messages in the Promptitude extension to help users distinguish between malformed repository URLs and repos that lack supported folder structures.
Changes:
- Added
validateRepositoryUrl()insyncManager.tsto reject GitHub URLs with extra path segments before making network calls. - Replaced the generic "No relevant files found" error with context-specific messages listing enabled sync types and the scanned branch.
- Updated
showPartialSyncSuccess()innotifications.tsto categorize and summarize failures in the toast notification.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/syncManager.ts | Added URL validation and improved error messages for empty sync results |
| src/utils/notifications.ts | Categorized failure counts in partial sync toast message |
| CHANGELOG.md | Documented the improvement under [Unreleased] |
You can also share your feedback on Copilot code review. Take the survey.
|
|
||
| const failParts: string[] = []; | ||
| if (badUrlCount > 0) { failParts.push(`${badUrlCount} bad URL${badUrlCount > 1 ? 's' : ''}`); } | ||
| if (badStructureCount > 0) { failParts.push(`${badStructureCount} incompatible structure`); } |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/utils/notifications.ts (1)
54-61: Consider using constants for error category markers.The string matching (
'Invalid URL','Incompatible repository','No sync types enabled') creates a tight coupling betweensyncManager.tsandnotifications.ts. If error message wording changes, categorization silently breaks.Consider extracting shared constants or using structured error objects with an explicit
categoryfield for more robust categorization.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/utils/notifications.ts` around lines 54 - 61, The current categorization loop in notifications.ts relies on hard-coded substrings ('Invalid URL', 'Incompatible repository', 'No sync types enabled') which couples it to syncManager.ts; instead define shared error category constants (e.g., INVALID_URL, INCOMPATIBLE_REPO, NO_SYNC_TYPES) in a common module or change syncManager.ts to throw/return structured error objects with a category property, then update the loop in notifications.ts to compare against those constants or inspect err.category (refer to the errors iteration and variables badUrlCount/badStructureCount/otherCount to locate the logic) so message wording changes won't break categorization.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/utils/notifications.ts`:
- Around line 50-70: The pluralization for the badStructureCount category is
inconsistent: update the failParts push for badStructureCount in
src/utils/notifications.ts (the block that builds failParts using badUrlCount,
badStructureCount, otherCount) to conditionally append an "s" when
badStructureCount > 1 (e.g., use `${badStructureCount} incompatible
structure${badStructureCount > 1 ? 's' : ''}`) so it matches the pluralization
pattern used for badUrlCount and otherCount and keeps the failSummary/message
strings correct.
---
Nitpick comments:
In `@src/utils/notifications.ts`:
- Around line 54-61: The current categorization loop in notifications.ts relies
on hard-coded substrings ('Invalid URL', 'Incompatible repository', 'No sync
types enabled') which couples it to syncManager.ts; instead define shared error
category constants (e.g., INVALID_URL, INCOMPATIBLE_REPO, NO_SYNC_TYPES) in a
common module or change syncManager.ts to throw/return structured error objects
with a category property, then update the loop in notifications.ts to compare
against those constants or inspect err.category (refer to the errors iteration
and variables badUrlCount/badStructureCount/otherCount to locate the logic) so
message wording changes won't break categorization.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b08b2502-1e29-4d27-a476-d5a10504d96b
📒 Files selected for processing (3)
CHANGELOG.mdsrc/syncManager.tssrc/utils/notifications.ts
| // Categorise failures so the summary toast is immediately actionable | ||
| let badUrlCount = 0; | ||
| let badStructureCount = 0; | ||
| let otherCount = 0; | ||
| for (const err of errors) { | ||
| if (err.includes('Invalid URL')) { | ||
| badUrlCount++; | ||
| } else if (err.includes('Incompatible repository') || err.includes('No sync types enabled')) { | ||
| badStructureCount++; | ||
| } else { | ||
| otherCount++; | ||
| } | ||
| } | ||
|
|
||
| const failParts: string[] = []; | ||
| if (badUrlCount > 0) { failParts.push(`${badUrlCount} bad URL${badUrlCount > 1 ? 's' : ''}`); } | ||
| if (badStructureCount > 0) { failParts.push(`${badStructureCount} incompatible structure`); } | ||
| if (otherCount > 0) { failParts.push(`${otherCount} other error${otherCount > 1 ? 's' : ''}`); } | ||
|
|
||
| const failSummary = failParts.length > 0 ? ` Failures: ${failParts.join(', ')}.` : ''; | ||
| const message = `⚠️ Partial sync: ${itemsCount} items updated from ${successCount}/${totalCount} repos.${failSummary}`; |
There was a problem hiding this comment.
Minor pluralization inconsistency for "incompatible structure".
The pluralization for badStructureCount doesn't add an 's' when count > 1, unlike the other categories.
✏️ Proposed fix
if (badUrlCount > 0) { failParts.push(`${badUrlCount} bad URL${badUrlCount > 1 ? 's' : ''}`); }
- if (badStructureCount > 0) { failParts.push(`${badStructureCount} incompatible structure`); }
+ if (badStructureCount > 0) { failParts.push(`${badStructureCount} incompatible structure${badStructureCount > 1 ? 's' : ''}`); }
if (otherCount > 0) { failParts.push(`${otherCount} other error${otherCount > 1 ? 's' : ''}`); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/utils/notifications.ts` around lines 50 - 70, The pluralization for the
badStructureCount category is inconsistent: update the failParts push for
badStructureCount in src/utils/notifications.ts (the block that builds failParts
using badUrlCount, badStructureCount, otherCount) to conditionally append an "s"
when badStructureCount > 1 (e.g., use `${badStructureCount} incompatible
structure${badStructureCount > 1 ? 's' : ''}`) so it matches the pluralization
pattern used for badUrlCount and otherCount and keeps the failSummary/message
strings correct.
When repository sync fails, Promptitude shows a generic "No relevant files found" for every failure — whether the configured URL is malformed (e.g. https://github.com/org/repo/tree/main/.github) or the repository simply doesn't use a supported folder layout. Users have no way to tell what went wrong without digging into debug logs.
syncManager.ts:validateRepositoryUrl()runs before any network call and rejects GitHub URLs that contain extra path segments (like/tree/…), with a clear message explaining what format is expectedAddedvalidateRepositoryUrl— runs before any network call and rejects GitHub URLs that contain extra path segments (like/tree/…), with a clear message explaining what format is expected.notifications.tsshowPartialSyncSuccess()to categorize failures in the summary toast (e.g. "Failures: 1 bad URL, 2 incompatible structure") so users can see the breakdown without clicking "Show Details."Updated showPartialSyncSuccess() to categorize failures in the summary toast (e.g. "Failures: 1 bad URL, 2 incompatible structure") so users can see the breakdown without clicking "Show Details.".CHANGELOG.md.../tree/main/.githubInvalid URL – expected https://github.com/owner/repo but got a sub-path (…)Incompatible repository – no .md/.txt files found under prompts/, instructions/ on branch "main"No sync types enabled – enable at least one of syncChatmode, syncInstructions, or syncPrompt in settings.⚠️ Partial sync completed! 0 items from 1/4 repositories.⚠️ Partial sync: 0 items from 1/4 repos. Failures: 1 bad URL, 2 incompatible structure.Verified with npm run compile — no errors.
Tested against repos: n
ventive/dev-prompt-kit(passes),itschanges/awesome-chatgpt-prompts(incompatible structure),openai/openai-cookbook/tree/main/.github(bad URL),openai/openai-cookbook(incompatible structure).Summary by CodeRabbit