jackwener/OpenCLI · error · CommandExecutionError

xiaohongshu/unfollow failed: ${err?.message ?? String(err)}

Error message

xiaohongshu/unfollow failed: ${err?.message ?? String(err)}

What it means

This is the catch-all wrapper at the end of the unfollow command: any thrown error that is not already a CliError (CommandExecutionError, AuthRequiredError, etc.) is re-wrapped as CommandExecutionError with the 'xiaohongshu/unfollow failed:' prefix. It preserves the original message so the underlying cause (network failure, page timeout, evaluate exception) is visible.

Source

Thrown at clis/xiaohongshu/unfollow.js:267

                'confirm-modal',
            );
            if (!confirmResult.ok) {
                throw new CommandExecutionError(
                    `xiaohongshu/unfollow: confirmation modal step failed (${confirmResult.kind ?? 'no kind reported'})`,
                );
            }

            // Step 3: verify the profile button text flipped back to 关注.
            const verifyRaw = unwrapEvaluateResult(await page.evaluate(buildVerifyFollowFlippedScript()));
            if (!verifyRaw || typeof verifyRaw !== 'object' || verifyRaw.ok !== true) {
                throw new CommandExecutionError(
                    `xiaohongshu/unfollow: ${verifyRaw?.reason ?? 'state verification failed'}`,
                );
            }
            return [{ status: 'unfollowed', user_id: userId, url }];
        } catch (err) {
            if (err instanceof CliError) throw err;
            throw new CommandExecutionError(
                `xiaohongshu/unfollow failed: ${err?.message ?? String(err)}`,
            );
        }
    },
});

export const __test__ = {
    assertUserId,
    buildClickUnfollowScript,
    buildConfirmModalScript,
    buildVerifyFollowFlippedScript,
};

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Read the wrapped err?.message in the output to find the real root cause and fix that first
  2. Retry the command if the cause was transient (network/browser hiccup)
  3. If the inner message points at a script crash, debug buildConfirmModalScript/buildVerifyFollowFlippedScript in the browser console
  4. Ensure custom steps inside the command throw CliError subclasses so they aren't double-wrapped
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await unfollow(userId);
} catch (err) {
  // message is 'xiaohongshu/unfollow failed: <root cause>'
  console.error('unfollow root cause:', err.message.replace('xiaohongshu/unfollow failed: ', ''));
  if (!isTransient(err)) throw err;
  await retryWithBackoff(() => unfollow(userId));
}

Prevention

When it happens

Trigger: Any non-CliError exception inside the command: page.evaluate threw a script error, page.wait timed out, browser disconnected, or a plain TypeError/undefined access occurred mid-flow.

Common situations: Browser crashed or tab closed mid-command; network drop during page.evaluate; a bug in one of the injected scripts threw inside the page context; refactored code threw a raw Error instead of CliError.

Related errors


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