TryGhost/Ghost · warning

The URL must be in a format like https://x.com/yourUsername

Error message

The URL must be in a format like https://x.com/yourUsername

What it means

Thrown by the platform-validator engine (createPlatformValidator) for the Twitter/X definition when input is URL-shaped but cannot be resolved to a valid x.com/twitter.com profile URL. The error message is declared in twitter.ts ('The URL must be in a format like https://x.com/yourUsername') but the actual throw happens in platform-validator.ts at: URL regex non-match (line 227), no path-type prefix match or empty remainder after the prefix (line 233, e.g. 'https://x.com/' with empty username), or the built canonical URL failing validator.isURL (line 263).

Source

Thrown at apps/admin/src/settings/app/utils/social-urls/twitter.ts:12

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

  1. Enter a full URL like 'https://x.com/yourUsername' or a bare handle 'yourUsername' (1–15 alphanumerics/underscores).
  2. If pasting, confirm the URL is on x.com or twitter.com — wrong-domain URLs throw invalidUrl.
  3. Strip whitespace and trailing slashes before submitting; an empty path after the domain is treated as invalidUrl.
  4. For non-throwing checks in code, use twitterUrlToHandle(url) which returns null on invalid input instead of throwing.

Example fix

// before — throws on wrong-domain or empty-path URL
const normalized = validateTwitterUrl(value);

// after — non-throwing pre-check, then validate
import {twitterUrlToHandle, validateTwitterUrl} from './twitter';
const trimmed = value.trim();
try {
    // twitterUrlToHandle returns null for non-x.com URLs / bad shapes
    if (trimmed && trimmed.includes('://') && twitterUrlToHandle(trimmed) === null) {
        setFieldError('twitter', 'Use an x.com or twitter.com URL');
    } else {
        setNormalized(validateTwitterUrl(trimmed));
    }
} catch (e) {
    setFieldError('twitter', e instanceof Error ? e.message : 'Invalid X/Twitter URL');
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Non-throwing pre-check using the URL→handle extractor
import {twitterUrlToHandle} from './twitter';
function looksLikeTwitterUrl(input: string): boolean {
    if (!input || !input.includes('://')) return true; // bare handles validated by the rule
    return twitterUrlToHandle(input) !== null;
}

Type guard

null

Try / catch

try {
    const normalized = validateTwitterUrl(value.trim());
} catch (e) {
    setFieldError('twitter', e instanceof Error ? e.message : 'Invalid X/Twitter URL');
}

Prevention

When it happens

Trigger: Input is detected as a URL (starts with http(s)://, //, www., or matches the bare x.com/twitter.com domain) but: the domain isn't x.com/twitter.com (e.g. 'https://facebook.com/user' → urlRegex fails → invalidUrl); OR the path after the domain is empty ('https://x.com/' → rest is '' → rest.length <= urlPrefix.length(0)); OR the assembled canonical URL fails validator.isURL. Note: bare non-URL handles that fail the username charset/length route to invalidUsername instead.

Common situations: User pasted a URL for the wrong platform into the X field; user entered 'https://x.com' with no handle; URL contains characters validator.isURL rejects; input had a scheme but a malformed host.

Related errors


AI-assisted analysis of TryGhost/Ghost@47d8b0e2ad (2026-08-13). Data as JSON: /api/errors/034036d1d49c582a. Report an issue: GitHub.