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

  1. Before adding, check rules.find(rule => rule.url == url) yourself and update the existing rule (updateRule) instead.
  2. Catch the error and surface 'this URL already has a rule' in the UI.
  3. 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

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


AI-assisted analysis of gildas-lormeau/SingleFile@517fb7c5cf (2026-09-01). Data as JSON: /api/errors/c15b1340b164b3b0. Report an issue: GitHub.