jackwener/OpenCLI · error · CommandExecutionError

Unknown GraphQL error

Error message

Unknown GraphQL error

What it means

After a successful HTTP response, gqlRequest checks json.errors, the standard GraphQL error channel. If the endpoint returned errors array entries, the first error's message is thrown; the literal 'Unknown GraphQL error' appears when the first error object has no message. This signals query-level failures (bad fields, syntax, auth) rather than transport issues.

Source

Thrown at clis/lesswrong/_helpers.js:21

export const DOMAIN = 'www.lesswrong.com';
const GRAPHQL_URL = `https://${DOMAIN}/graphql`;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- GraphQL responses vary per query
export async function gqlRequest(query) {
    const resp = await fetch(GRAPHQL_URL, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            Accept: 'application/json',
        },
        body: JSON.stringify({ query }),
        signal: AbortSignal.timeout(15000),
    });
    if (!resp.ok) {
        throw new CommandExecutionError(`LessWrong API returned HTTP ${resp.status}`);
    }
    const json = (await resp.json());
    if (json.errors?.length) {
        throw new CommandExecutionError(json.errors[0]?.message ?? 'Unknown GraphQL error');
    }
    return json.data;
}
export function gqlEscape(str) {
    return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
}
export function stripHtml(html) {
    if (!html)
        return '';
    return html
        .replace(/<script[^>]*>.*?<\/script>/gis, ' ')
        .replace(/<style[^>]*>.*?<\/style>/gis, ' ')
        .replace(/<[^>]+>/g, ' ')
        .replace(/\s+/g, ' ')
        .trim();
}
export function daysAgo(n) {
    const d = new Date();

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Inspect the query string for invalid/renamed fields and test it in the LessWrong GraphQL playground (lesswrong.com/graphql)
  2. Rebuild the query from the current LessWrong GraphQL schema
  3. Check gqlEscape usage when interpolating user strings to avoid query syntax errors
  4. If errors:[{message:null}], log json.errors fully to see the underlying code/extensions

Example fix

// before
const query = `query { user(input: {selector: {slug: "${slug}"}}) { result { _id } } }`;
// after
const query = `query { user(input: {selector: {slug: "${gqlEscape(slug)}"}}) { result { _id } } }`;
Defensive patterns

Strategy: type-guard

Validate before calling

// validate interpolated values before building the query
if (!/^[a-z0-9-]*$/.test(slug)) throw new Error('invalid slug for query');

Type guard

const hasGraphqlErrors = (json) => Array.isArray(json?.errors) && json.errors.length > 0;

Try / catch

try {
  const data = await gqlRequest(query);
} catch (e) {
  if (String(e.message) === 'Unknown GraphQL error' || /GraphQL/i.test(e.message)) {
    console.error('GraphQL query failed — validate fields against current LessWrong schema');
  } else throw e;
}

Prevention

When it happens

Trigger: The GraphQL query references a nonexistent field/type, has a syntax error, requests an unauthenticated field, or LessWrong returns errors:[{}] with no message text.

Common situations: LessWrong GraphQL schema changed or a field was renamed (e.g. old queries using removed fields); dynamically built query strings with malformed interpolation; internal resolver error returned without a message.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/1683ec8e529152c1. Report an issue: GitHub.