jackwener/OpenCLI · warning · CliError

EMPTY_RESULT

EMPTY_RESULT

Error message

No track found for: ${query}

What it means

findTrackUri performs a Spotify search (type=track, limit=1) and throws EMPTY_RESULT when Spotify returns no usable track in the first result slot — i.e. getFirstSpotifyTrack(data) yields nothing. It distinguishes 'the API worked but found nothing' from API_ERROR so callers can treat it as an empty-search condition rather than a failure.

Source

Thrown at clis/spotify/spotify.js:98

    const token = await getToken();
    const res = await fetch(`https://api.spotify.com/v1${path}`, {
        method,
        headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
        body: body ? JSON.stringify(body) : undefined,
    });
    if (res.status === 204 || res.status === 202)
        return null;
    if (!res.ok) {
        const err = await res.json().catch(() => ({}));
        throw new CliError('API_ERROR', err?.error?.message || `Spotify API error ${res.status}`);
    }
    return res.json();
}
async function findTrackUri(query) {
    const data = await api('GET', `/search?q=${encodeURIComponent(query)}&type=track&limit=1`);
    const track = getFirstSpotifyTrack(data);
    if (!track)
        throw new CliError('EMPTY_RESULT', `No track found for: ${query}`);
    return track;
}
function openBrowser(url) {
    const cmd = process.platform === 'win32' ? `start "" "${url}"` : process.platform === 'darwin' ? `open "${url}"` : `xdg-open "${url}"`;
    exec(cmd);
}
// ── Commands ──────────────────────────────────────────────────────────────────
cli({
    site: 'spotify',
    name: 'auth',
    access: 'write',
    description: 'Authenticate with Spotify (OAuth — run once)',
    strategy: Strategy.PUBLIC,
    browser: false,
    args: [],
    columns: ['status'],
    func: async () => {
        assertSpotifyCredentialsConfigured(credentials, ENV_FILE);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Simplify the query: use 'artist track' without extra noise like '(official video)' or file extensions.
  2. Check spelling and try the artist name plus partial title.
  3. Verify the track exists by searching it in the Spotify app/web player.
  4. In scripts, sanitize metadata-derived queries before passing them.

Example fix

// before
opencli spotify play "track_unknown_xyz"
// after
opencli spotify play "Daft Punk One More Time"
Defensive patterns

Strategy: fallback

Validate before calling

const q = rawQuery.trim();
if (!q || !/\p{L}/u.test(q)) { console.error('Query has no usable search terms'); return null; }

Try / catch

try {
  const track = await findTrackUri(query);
} catch (e) {
  if (e.code === 'EMPTY_RESULT') {
    const simplified = query.split(/\s+/).slice(0, 3).join(' '); // retry with fewer terms
    return findTrackUri(simplified);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling findTrackUri (via play-related commands) with a query string that matches zero tracks: nonsense strings, heavy misspellings, or a query containing only characters Spotify's search ignores.

Common situations: Users typing a track name with typos; searching regional/obscure tracks not in Spotify's catalog; scripts building queries from metadata (e.g. filename-derived) producing garbage queries; non-Latin scripts or special-character-only queries.

Related errors


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