TryGhost/Ghost · warning
Your Username is not a valid Twitter Username
Error message
Your Username is not a valid Twitter Username
What it means
Thrown by the platform-validator engine for the Twitter/X definition when the username itself is invalid, OR when handleToUrl is called with an empty handle. Message declared in twitter.ts ('Your Username is not a valid Twitter Username'); thrown in platform-validator.ts at: query/fragment present in a non-fullPath username (line 247), the username rule check fails (line 255), or handleToUrl receives an empty handle (line 280). The X rule is ASCII alphanumerics plus underscore, length 1–15.
Source
Thrown at apps/admin/src/settings/app/utils/social-urls/twitter.ts:13
import {createPlatformValidator} from './platform-validator';
// X handles are ASCII-only by platform rule: 1–15 letters, numbers or underscores.
// twitter.com URLs are accepted and canonicalised to x.com.
const twitter = createPlatformValidator({
domains: ['x.com', 'twitter.com'],
www: false,
pathTypes: [
{urlPrefix: '', storagePrefix: '@', rule: {extra: '_', min: 1, max: 15}}
],
errors: {
invalidUrl: 'The URL must be in a format like https://x.com/yourUsername',
invalidUsername: 'Your Username is not a valid Twitter Username'
}
});
export const validateTwitterUrl = twitter.validate;
export const twitterHandleToUrl = twitter.handleToUrl;
export const twitterUrlToHandle = twitter.urlToHandle;
View on GitHub (pinned to 47d8b0e2ad)
Solutions
- Use a handle of 1–15 ASCII letters, digits, or underscores only — no dots, hyphens, or spaces.
- Guard handleToUrl against empty strings at the call site before invoking it.
- Strip query strings and fragments from URLs before validation (they're not part of an X handle).
- When rendering stored handles, wrap handleToUrl in try-catch and fall back to omitting the link.
Example fix
// before — throws on empty/corrupt stored handle or out-of-rule handle
const url = twitterHandleToUrl(profile.x);
// after — guard empty, try-catch the rest
const handle = profile.x?.trim();
if (!handle) {
return null;
}
try {
return twitterHandleToUrl(handle);
} catch {
return null;
} Defensive patterns
Strategy: try-catch
Validate before calling
// Validate the handle shape before calling handleToUrl
function isValidTwitterHandleShape(h: string): boolean {
return /^[a-zA-Z0-9_]{1,15}$/.test(h);
} Type guard
null
Try / catch
const handle = profile.x?.trim();
if (!handle) return null;
try {
return twitterHandleToUrl(handle);
} catch {
return null;
} Prevention
- Use 1–15 ASCII letters/digits/underscores only — no dots, hyphens, or spaces.
- Guard handleToUrl against empty strings.
- Strip query strings and fragments from URLs before validation.
- Wrap handleToUrl in try-catch when rendering from stored data.
When it happens
Trigger: Username fails the compiled rule: contains characters outside [a-zA-Z0-9_] (e.g. 'user.name', 'user-name'); length outside 1–15 (empty, or >15 chars like 'this_handle_is_too_long'); contains a '?' or '#' (query/fragment) in a URL username segment; OR handleToUrl('') with an empty stored handle.
Common situations: User typed a handle with a dot or hyphen (not allowed on X); handle longer than 15 characters; rendering a stored handle that's empty due to data corruption; user included a trailing query string in the URL.
Related errors
- The URL must be in a format like https://x.com/yourUsername
- 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://www.linkedin.com/in
- Your Username is not a valid LinkedIn Username
AI-assisted analysis of TryGhost/Ghost@47d8b0e2ad (2026-08-13).
Data as JSON: /api/errors/aadbdf0bf0c16314.
Report an issue: GitHub.