TryGhost/Ghost · warning
Your Username is not a valid YouTube Username
Error message
Your Username is not a valid YouTube Username
What it means
Thrown by the platform-validator engine for the YouTube definition when the username for the matched path type is invalid, or handleToUrl is called empty. Message declared in youtube.ts ('Your Username is not a valid YouTube Username'); thrown in platform-validator.ts at: query/fragment in username (line 247), username rule check failure (line 255), or empty handle in handleToUrl (line 280). The rule depends on the path type: @handle (Unicode, 3–30 chars, ._-, no boundary ._-, no consecutive dots), user/ (._-, 1–50), channel/ (must match /^UC[a-zA-Z0-9_-]{22}$/).
Source
Thrown at apps/admin/src/settings/app/utils/social-urls/youtube.ts:17
import {createPlatformValidator} from './platform-validator';
// YouTube profile URLs come in three shapes: modern @handles (3–30 chars,
// letters/numbers/._- with no boundary punctuation — non-Latin scripts are
// supported), legacy /user/ usernames and /channel/ IDs (UC + 22 chars).
// Bare input defaults to an @handle.
const youtube = createPlatformValidator({
domains: ['youtube.com'],
www: true,
pathTypes: [
{urlPrefix: '@', storagePrefix: '@', rule: {unicode: true, extra: '._-', min: 3, max: 30, notAtBoundary: '._-', notConsecutive: '.'}},
{urlPrefix: 'user/', storagePrefix: 'user/', rule: {extra: '._-', min: 1, max: 50}},
{urlPrefix: 'channel/', storagePrefix: 'channel/', rule: {patterns: [/^UC[a-zA-Z0-9_-]{22}$/]}}
],
errors: {
invalidUrl: 'The URL must be in a format like https://www.youtube.com/@yourUsername, https://www.youtube.com/user/yourUsername, or https://www.youtube.com/channel/yourChannelId',
invalidUsername: 'Your Username is not a valid YouTube Username'
}
});
export const validateYouTubeUrl = youtube.validate;
export const youtubeHandleToUrl = youtube.handleToUrl;
export const youtubeUrlToHandle = youtube.urlToHandle;
View on GitHub (pinned to 47d8b0e2ad)
Solutions
- Match the rule for the chosen path type: @handle (3–30, Unicode, no boundary ._-, no consecutive dots), user/ (1–50, ._-.), or channel/ (UC + 22 chars).
- Guard handleToUrl against empty strings before calling.
- Strip query strings and fragments from URLs before validation.
- Avoid mixing conventions (e.g. user/@name) — a leftover @ after a structural prefix is intentionally not stripped.
Example fix
// before — throws on empty/corrupt stored handle or out-of-rule handle
const url = youtubeHandleToUrl(profile.youtube);
// after — guard empty, try-catch the rest
const handle = profile.youtube?.trim();
if (!handle) {
return null;
}
try {
return youtubeHandleToUrl(handle);
} catch {
return null;
} Defensive patterns
Strategy: try-catch
Validate before calling
// Validate the handle shape for the matched YouTube path type
function isValidYouTubeHandleShape(h: string): boolean {
if (!h) return false;
if (h.startsWith('@')) {
const name = h.slice(1);
return [...name].length >= 3 && [...name].length <= 30;
}
if (h.startsWith('channel/')) {
return /^UC[a-zA-Z0-9_-]{22}$/.test(h.slice('channel/'.length));
}
if (h.startsWith('user/')) {
const name = h.slice('user/'.length);
return name.length >= 1 && name.length <= 50;
}
return false;
} Type guard
null
Try / catch
const handle = profile.youtube?.trim();
if (!handle) return null;
try {
return youtubeHandleToUrl(handle);
} catch {
return null;
} Prevention
- Match the rule for the chosen path type: @handle (3–30, Unicode, no boundary ._-, no consecutive dots), user/ (1–50), channel/ (UC + 22 chars).
- Guard handleToUrl against empty strings.
- Strip query strings and fragments from URLs before validation.
- Don't mix conventions (user/@name).
When it happens
Trigger: For @handles: length outside 3–30, disallowed characters, leading/trailing ._- (notAtBoundary), or consecutive dots. For user/: length outside 1–50 or charset. For channel/: the ID doesn't match UC + 22 alphanumerics/_-. Also: a URL username segment contains '?' or '#' (query/fragment); OR handleToUrl('') with an empty stored handle.
Common situations: User typed an @handle under 3 or over 30 characters; channel ID malformed (not UC-prefixed or wrong length); rendering an empty stored handle; user appended a query string; user mixed conventions ('user/@name' leaves a leftover @ that the rule rejects).
Related errors
- The URL must be in a format like https://www.youtube.com/@yo
- The URL must be in a format like @username@instance.tld or h
- Your Username is not a valid Mastodon Username
- The URL must be in a format like https://x.com/yourUsername
- Your Username is not a valid Twitter Username
AI-assisted analysis of TryGhost/Ghost@47d8b0e2ad (2026-08-13).
Data as JSON: /api/errors/f50779001edcca97.
Report an issue: GitHub.