jackwener/OpenCLI · error · Error
Unexpected code payload shape: ${codeUrl}
Error message
Unexpected code payload shape: ${codeUrl} What it means
Thrown by getRawCode when the /resource/post/code/<postId> endpoint returns a 200 JSON payload that lacks string-typed html and css fields. The library expects { html, css } (and possibly more) and treats any other shape as unusable for generating exports.
Source
Thrown at clis/uiverse/_shared.js:113
routeData = await fetchJsonInBrowser(page, routeUrl);
}
if (!routeData?.post?.id) {
throw new Error(`Could not resolve post.id from the component page: ${normalized.url}`);
}
return {
...normalized,
post: routeData.post,
routeData,
};
}
export async function getRawCode(page, postId) {
const codeUrl = `${UIVERSE_BASE_URL}/resource/post/code/${postId}?v=1&_data=${encodeURIComponent(CODE_DATA_KEY)}`;
const payload = await fetchJsonInBrowser(page, codeUrl);
if (typeof payload?.html !== 'string' || typeof payload?.css !== 'string') {
throw new Error(`Unexpected code payload shape: ${codeUrl}`);
}
return payload;
}
export function inferLanguage(target, post) {
if (target === 'react') return 'tsx';
if (target === 'vue') return 'vue';
if (target === 'html') return post?.isTailwind ? 'html+tailwind' : 'html';
if (target === 'css') return 'css';
return 'text';
}
export function getCodeLength(code) {
return String(code || '').length;
}
function normalizeExportTarget(target) {
return String(target || '').trim().toLowerCase() === 'vue' ? 'Vue' : 'React';View on GitHub (pinned to 49907e53dc)
Solutions
- Log the payload to see the actual shape returned for that postId
- If keys changed, update getRawCode in clis/uiverse/_shared.js to match the new response schema
- Re-fetch post details to ensure you are using a fresh post.id (a stale id may yield an error-shaped payload)
- Test the same codeUrl manually in the logged-in browser to compare responses
Example fix
// before
const payload = await getRawCode(page, postId); // throws 'Unexpected code payload shape'
// after
try {
var payload = await getRawCode(page, postId);
} catch (e) {
console.error(e.message, '— inspect', `https://uiverse.io/resource/post/code/${postId}?v=1&_data=routes/resource.post.code.$id`);
throw e;
} Defensive patterns
Strategy: type-guard
Validate before calling
const payload = await fetchJsonInBrowser(page, codeUrl);
const isCodePayload = (p) => typeof p?.html === 'string' && typeof p?.css === 'string';
if (!isCodePayload(payload)) {
console.error('Unexpected payload keys:', Object.keys(payload || {}));
throw new Error('code endpoint schema changed');
} Type guard
const hasCodeShape = (p) => p !== null && typeof p === 'object' && typeof p.html === 'string' && typeof p.css === 'string';
Try / catch
try {
const code = await getRawCode(page, postId);
} catch (e) {
if (e.message.startsWith('Unexpected code payload shape')) {
console.error(`Schema drift for postId ${postId}; skipping.`);
return null; // or re-fetch details for a fresh postId
}
throw e;
} Prevention
- Log Object.keys(payload) on failure to spot renamed fields immediately
- Keep a fresh post.id — stale/deleted posts can yield error-shaped payloads
- Pin tests against a known-good component so schema drift is caught early
- Check uiverse.io changelog/behavior after any site update before bulk runs
When it happens
Trigger: Uiverse changed the code-resource loader response shape (e.g. renamed html/css keys or nested them); the postId is valid but the component has no stored code (empty strings are fine, but null/missing is not); the endpoint returned a generic Remix error JSON ({ message: ... }) with 200; component saved with Tailwind-only or an alternate code representation.
Common situations: Scraping right after a uiverse.io backend migration; components created with newer formats the endpoint represents differently; requesting a code resource for a deleted or private post whose endpoint returns an error object instead of failing the request.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- ${label} returned an unexpected payload shape; expected an o
- Booking.com extractor returned malformed items
- Booking.com extractor returned malformed hotel row
- douyin hashtag ${action}: API returned malformed "${field}"
- ${command} selector drift${reason}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/6370d24cd477e527.
Report an issue: GitHub.