gildas-lormeau/SingleFile · error · Error
URL already exists
Error message
URL already exists
What it means
addRule enforces unique URLs across rules: before pushing the new rule it searches existing rules for one whose url matches exactly (==), and throws 'URL already exists' on a duplicate. Rules are keyed by URL, so two rules for the same URL would be ambiguous.
Source
Thrown at src/core/bg/config.js:678
async function getProfile(profileName) {
const profileKey = PROFILE_NAME_PREFIX + profileName;
const data = await configStorage.get([profileKey]);
return data[profileKey];
}
async function setProfile(profileName, profileData) {
const profileKey = PROFILE_NAME_PREFIX + profileName;
await configStorage.set({ [profileKey]: profileData });
}
async function addRule(url, profile, autoSaveProfile) {
if (!url) {
throw new Error("URL is empty");
}
const rules = await getRules();
if (rules.find(rule => rule.url == url)) {
throw new Error("URL already exists");
}
rules.push({
url,
profile,
autoSaveProfile
});
await configStorage.set({ rules });
}
async function deleteRule(url) {
if (!url) {
throw new Error("URL is empty");
}
const rules = await getRules();
await configStorage.set({ rules: rules.filter(rule => rule.url != url) });
}
async function deleteRules(profileName) {View on GitHub (pinned to 517fb7c5cf)
Solutions
- Before adding, check rules.find(rule => rule.url == url) yourself and update the existing rule (updateRule) instead.
- Catch the error and surface 'this URL already has a rule' in the UI.
- Normalize/trim the URL before comparison to avoid near-duplicates with different whitespace.
Example fix
// before await addRule(url, profile); // after const rules = await getRules(); if (rules.some(r => r.url == url)) await updateRule(url, url, profile, autoSaveProfile); else await addRule(url, profile, autoSaveProfile);
Defensive patterns
Strategy: try-catch
Validate before calling
const rules = await getRules(); if (rules.some(r => r.url == url)) await updateRule(url, url, profile, autoSaveProfile); else await addRule(url, profile, autoSaveProfile);
Try / catch
try { await addRule(url, profile, asp); } catch (e) { if (e.message === 'URL already exists') notify('This URL already has a rule'); else throw e; } Prevention
- Pre-check duplicates in the UI before submit
- Disable submit when the URL matches an existing rule
- Normalize URLs (trim) before comparisons
When it happens
Trigger: Calling addRule('https://example.com/*', profile) when a rule with exactly that URL already exists in config storage; or calling addRule twice with the same URL.
Common situations: User re-adding a rule that was auto-saved earlier (autoSaveProfile rules); a settings page that doesn't pre-check duplicates before submitting.
Related errors
- New URL already exists
- URL is empty
- URL not found
- Duplicate profile name
- Default settings cannot be deleted
AI-assisted analysis of gildas-lormeau/SingleFile@517fb7c5cf (2026-09-01).
Data as JSON: /api/errors/c15b1340b164b3b0.
Report an issue: GitHub.