jackwener/OpenCLI · warning
index must be a positive integer
Error message
index must be a positive integer
What it means
The unsave command's injected browser script converts the 1-based --index argument to a 0-based idx and validates it before use. If args.index is not a positive integer (0, negative, fractional, or non-numeric), the script throws immediately. This is an argument-validation guard, not a network failure.
Source
Thrown at clis/instagram/unsave.js:23
access: 'write',
description: 'Unsave (remove bookmark) an Instagram post',
domain: 'www.instagram.com',
args: [
{
name: 'username',
required: true,
positional: true,
help: 'Username of the post author',
},
{ name: 'index', type: 'int', default: 1, help: 'Post index (1 = most recent)' },
],
columns: ['status', 'user', 'post'],
pipeline: [
{ navigate: 'https://www.instagram.com' },
{ evaluate: `(async () => {
const username = \${{ args.username | json }};
const idx = \${{ args.index }} - 1;
if (!Number.isInteger(idx) || idx < 0) throw new Error('index must be a positive integer');
const headers = { 'X-IG-App-ID': '936619743392459' };
const opts = { credentials: 'include', headers };
async function readInstagramJson(response, label) {
try {
return await response.json();
} catch {
throw new Error(label + ' returned invalid JSON');
}
}
function getPostFromFeed(feed, label) {
if (!feed || typeof feed !== 'object' || !Array.isArray(feed.items)) {
throw new Error(label + ' returned malformed items payload');
}
if (idx >= feed.items.length) throw new Error('Post index ' + (idx + 1) + ' not found');
const post = feed.items[idx];
const pkRaw = post?.pk ?? post?.id;
const pk = typeof pkRaw === 'number' ? String(pkRaw) : (typeof pkRaw === 'string' ? pkRaw.trim() : '');
if (!/^\\d+$/.test(pk)) throw new Error(label + ' returned malformed post row');View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a 1-based positive integer, e.g. --index 1 for the first post.
- Check the value is an integer greater than 0 before invoking.
- If scripting, coerce with Number() and Number.isInteger() before calling.
Example fix
// before npx cli instagram unsave --username someuser --index 0 // after npx cli instagram unsave --username someuser --index 1
Defensive patterns
Strategy: validation
Validate before calling
const idx = Number(index);
if (!Number.isInteger(idx) || idx < 1) throw new Error('index must be a positive integer, got: ' + index); Type guard
const isValidIndex = (n) => Number.isInteger(n) && n >= 1;
Prevention
- Remember the CLI index is 1-based
- Validate numeric CLI args in wrapper scripts
- Coerce string args with Number() before passing
When it happens
Trigger: Calling unsave with --index 0, --index -1, --index 2.5, or a non-numeric value; the check `!Number.isInteger(idx) || idx < 0` fails where idx = index - 1.
Common situations: Typing 0-based index by habit (CLI expects 1-based); passing a string/empty value from a script; off-by-one confusion when the saved post is the first in the list.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Argument "media" is required.
- Instagram story currently supports a single media item.
- Post index ' + (idx + 1) + ' not found
- ${label} is required
- ${label} must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/990b5fa35e3853e3.
Report an issue: GitHub.