{"record":{"id":"1c9f4a390e986bc5","repo":"TryGhost/Ghost","slug":"your-username-is-not-a-valid-instagram-username","errorCode":null,"errorMessage":"Your Username is not a valid Instagram Username","messagePattern":"Your Username is not a valid Instagram Username","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"apps/admin/src/settings/app/utils/social-urls/instagram.ts","lineNumber":24,"sourceCode":"// consecutive periods. Threads reuses this rule — Threads accounts are\n// Instagram accounts.\nexport const INSTAGRAM_USERNAME_RULE: UsernameRule = {\n    extra: '._',\n    min: 1,\n    max: 30,\n    notAtBoundary: '.',\n    notConsecutive: '.'\n};\n\nconst instagram = createPlatformValidator({\n    domains: ['instagram.com'],\n    www: true,\n    pathTypes: [\n        {urlPrefix: '', storagePrefix: '', rule: INSTAGRAM_USERNAME_RULE}\n    ],\n    errors: {\n        invalidUrl: 'The URL must be in a format like https://www.instagram.com/yourUsername',\n        invalidUsername: 'Your Username is not a valid Instagram Username'\n    }\n});\n\nexport const validateInstagramUrl = instagram.validate;\nexport const instagramHandleToUrl = instagram.handleToUrl;\nexport const instagramUrlToHandle = instagram.urlToHandle;\n","sourceCodeStart":6,"sourceCodeEnd":31,"githubUrl":"https://github.com/TryGhost/Ghost/blob/47d8b0e2ad2fd4757d3bc45f46c3ac165ff8a1fe/apps/admin/src/settings/app/utils/social-urls/instagram.ts#L6-L31","documentation":"Thrown by the platform-validator engine for the Instagram definition when the username is invalid, or handleToUrl is called empty. Message declared in instagram.ts ('Your Username is not a valid Instagram Username'); thrown in platform-validator.ts at: query/fragment in username (line 247), username rule check failure (line 255 — INSTAGRAM_USERNAME_RULE: 2–30 chars, allowed charset, no boundary/consecutive dots), or empty handle in handleToUrl (line 280).","triggerScenarios":"Username fails INSTAGRAM_USERNAME_RULE: length outside 2–30; contains disallowed characters; starts or ends with a dot (notAtBoundary: '.'); contains consecutive dots '..' (notConsecutive: '.'); OR handleToUrl('') with an empty stored handle; OR a URL username segment contains '?' or '#' (query/fragment).","commonSituations":"User typed a 1-character or >30-character handle; handle with leading/trailing dot ('.user'); handle with consecutive dots ('us..er'); rendering an empty stored handle; user appended a query string to the URL.","solutions":["Use an Instagram handle of 2–30 characters in the allowed charset, with no leading/trailing dot and no consecutive dots.","Guard handleToUrl against empty strings before calling.","Strip query strings and fragments from URLs before validation.","When rendering stored handles, wrap handleToUrl in try-catch and omit the link on failure."],"exampleFix":"// before — throws on empty/corrupt stored handle or out-of-rule handle\nconst url = instagramHandleToUrl(profile.instagram);\n\n// after — guard empty, try-catch the rest\nconst handle = profile.instagram?.trim();\nif (!handle) {\n    return null;\n}\ntry {\n    return instagramHandleToUrl(handle);\n} catch {\n    return null;\n}","handlingStrategy":"try-catch","validationCode":"// Validate the handle shape before calling handleToUrl\nfunction isValidInstagramHandleShape(h: string): boolean {\n    if (!h || [...h].length < 2 || [...h].length > 30) return false;\n    if (h.startsWith('.') || h.endsWith('.')) return false;\n    if (h.includes('..')) return false;\n    return true; // full charset check delegated to the validator\n}","typeGuard":"null","tryCatchPattern":"const handle = profile.instagram?.trim();\nif (!handle) return null;\ntry {\n    return instagramHandleToUrl(handle);\n} catch {\n    return null;\n}","preventionTips":["Use 2–30 characters with no leading/trailing dot and no consecutive dots.","Guard handleToUrl against empty strings.","Strip query strings and fragments from URLs before validation.","Wrap handleToUrl in try-catch when rendering from stored data."],"tags":["instagram","social-urls","validation"],"backgroundTag":null,"analyzedSha":"47d8b0e2ad2fd4757d3bc45f46c3ac165ff8a1fe","analyzedAt":"2026-08-13T01:25:26.651Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}