jackwener/OpenCLI · error · CommandExecutionError

Midjourney settings panel returned an unexpected shape

Error message

Midjourney settings panel returned an unexpected shape

What it means

CommandExecutionError from readSiteSettings. After opening the settings panel it evaluates the DOM to build a settings object (model, imageResolution, speed, raw, speed, videoResolution, videoBatchSize); if the evaluation returns null or a non-object the shape is unexpected and it throws before the required-field check.

Source

Thrown at clis/midjourney/utils.js:1392

      if (menu && /^\d+(?:\.\d+)?$/.test(menu.textContent?.trim() || '')) {
        version = menu.textContent.trim();
        break;
      }
    }
    const imageResolution = selectedNear('Version', ['Standard', 'HD']);
    const personalization = selectedNear('Personalize', ['On', 'Off']);
    const raw = selectedNear('Raw', ['Standard', 'Raw']);
    return {
      model: version ? `v${version}` : null,
      imageResolution: imageResolution ? imageResolution.toLowerCase().replace('standard', 'sd') : null,
      personalization: personalization ? personalization === 'On' : null,
      raw: raw ? raw === 'Raw' : null,
      speed: (selectedNear('Speed', ['Relax', 'Fast', 'Turbo']) || '').toLowerCase() || null,
      videoResolution: (selectedNear('Video Resolution', ['SD', 'HD']) || '').toLowerCase() || null,
      videoBatchSize: Number(selectedNear('Video Batch Size', ['1', '2', '4'])) || null,
    };
  }));
  if (!result || typeof result !== 'object') throw new CommandExecutionError('Midjourney settings panel returned an unexpected shape');
  const missing = ['model', 'imageResolution', 'speed'].filter((key) => result[key] == null);
  if (missing.length) {
    throw new CommandExecutionError(`Midjourney settings panel is missing required field(s): ${missing.join(', ')}`);
  }
  return result;
}

export async function selectSiteSetting(page, anchorText, candidates, targetText) {
  await readSiteSettings(page);
  const target = unwrapEvaluateResult(await page.evaluate((anchorLabel, values, wanted) => {
    const visible = (element) => {
      const rect = element.getBoundingClientRect();
      return rect.width > 0 && rect.height > 0 && getComputedStyle(element).display !== 'none';
    };
    document.querySelectorAll('[data-opencli-setting-target]').forEach((node) => node.removeAttribute('data-opencli-setting-target'));
    const anchors = [...document.querySelectorAll('h2,a,div,span')]
      .filter((node) => node.textContent?.trim() === anchorLabel && visible(node))
      .sort((left, right) => left.children.length - right.children.length);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Call isSettingsPanelVisible first and open the panel via toggleSettingsPanel before reading
  2. Increase the wait after opening the panel so settings render
  3. Update the CLI to match current settings panel DOM
  4. Log the raw evaluate result to diagnose the shape mismatch

Example fix

// before
const settings = await readSiteSettings(page);
// after
if (!(await isSettingsPanelVisible(page))) {
  await toggleSettingsPanel(page);
  await page.wait(0.5);
}
const settings = await readSiteSettings(page);
Defensive patterns

Strategy: validation

Validate before calling

if (!(await isSettingsPanelVisible(page))) {
  await toggleSettingsPanel(page);
  await page.wait(0.5);
}

Type guard

const isSettingsShape = (r) => r != null && typeof r === 'object';

Try / catch

try {
  const settings = await readSiteSettings(page);
} catch (e) {
  if (String(e.message).includes('unexpected shape')) {
    await toggleSettingsPanel(page); await page.wait(1);
    return readSiteSettings(page);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling readSiteSettings (directly or via selectSiteSetting) when the settings panel is not visible or its DOM did not yield the expected structure, so the evaluate callback returns null/undefined.

Common situations: Settings panel failed to open (toggle silently failed); Midjourney settings markup changed; page.evaluate wrapper returning an unwrapped null; navigation/rerender mid-read.

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


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