Skip to content

fix(instagram): explain unavailable posts - #98

Merged
rosethornbush merged 1 commit into
mainfrom
fix/instagram-errors
Sep 5, 2026
Merged

fix(instagram): explain unavailable posts#98
rosethornbush merged 1 commit into
mainfrom
fix/instagram-errors

Conversation

@rosethornbush

@rosethornbush rosethornbush commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

instagram's age-gated posts were showing up as generic fetch failures. commands now explain when instagram requires login, with a fallback message when it doesn't provide public media.

automatic embeds keep their existing failure reaction.

@changeset-bot

changeset-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2e74932

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 4da76e01-5159-44f4-9f2d-6fd32aa4b1ca

📥 Commits

Reviewing files that changed from the base of the PR and between d3dba94 and 2e74932.

📒 Files selected for processing (3)
  • apps/api/src/index.ts
  • packages/logging/src/main.ts
  • packages/platforms/src/platforms/instagram.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change classifies Instagram fetch failures by page content, records upstream reasons in error context, and maps those reasons to specific API error events with dedicated status codes.

Changes

Instagram error classification

Layer / File(s) Summary
Define Instagram error contracts and upstream context
packages/logging/src/main.ts
ErrorContext now records upstream_reason. Logging defines age-restricted, post-unavailable, and media-unavailable Instagram errors with statuses 403, 404, and 502.
Classify Instagram page failures
packages/platforms/src/platforms/instagram.ts
The fetch flow parses media only when a data script exists. It maps page text to age-restricted, post-unavailable, or media-unavailable errors.
Map upstream reasons to API events
apps/api/src/index.ts
The scrape handler selects the matching Instagram error event and reuses one computed error context for the problem and log context.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 2e749

Instagram fetch failures now return clearer age-restriction, unavailable-post, and fallback media-unavailable responses, with no concrete merge-blocking risk identified.

Sequence Diagram(s)

sequenceDiagram
  participant InstagramFetch
  participant InstagramPage
  participant ScrapeHandler
  participant Logging
  InstagramFetch->>InstagramPage: inspect data script and page text
  InstagramPage-->>InstagramFetch: media data or failure text
  InstagramFetch->>Logging: throw reason-specific error
  Logging-->>ScrapeHandler: provide upstream_reason
  ScrapeHandler->>ScrapeHandler: select Instagram error event
  ScrapeHandler-->>Logging: reuse error context for problem and log
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: improved Instagram handling and explanation for unavailable posts.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/instagram-errors

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
embedly-docs 2e74932 Commit Preview URL

Branch Preview URL
Sep 05 2026, 01:45 AM

@greptile-apps

greptile-apps Bot commented Sep 5, 2026

Copy link
Copy Markdown

Greptile Summary

This PR distinguishes Instagram age-restricted and unavailable posts from generic platform failures while preserving the existing automatic-embed failure behavior.

  • Extracts a structured Instagram failure reason from platform errors.
  • Maps known reasons to explanatory API problems for command responses.
  • Falls back to a public-media-unavailable explanation when Instagram provides no media.
  • The new exact-text classification lacks regression fixtures for its supported responses.

Confidence Score: 4/5

The PR appears safe to merge, with a non-blocking request to add regression coverage for the external HTML classifications.

The reason propagation and client behavior are internally consistent, and no functional failure was established; the remaining concern is that exact Instagram text matching is introduced without fixtures covering either specialized branch.

Files Needing Attention: packages/platforms/src/platforms/instagram.ts

Important Files Changed

Filename Overview
packages/platforms/src/platforms/instagram.ts Adds body-text fallback classification for age-restricted, unavailable, and missing-public-media Instagram responses; representative regression coverage is absent.
apps/api/src/index.ts Maps structured Instagram failure reasons to the corresponding explanatory problem responses.
packages/logging/src/main.ts Adds upstream-reason extraction and defines the three Instagram-facing error events.

Sequence Diagram

sequenceDiagram
  participant Bot
  participant API
  participant InstagramPlatform
  participant Instagram

  Bot->>API: POST /platforms/scrape
  API->>InstagramPlatform: fetch(post ID)
  InstagramPlatform->>Instagram: GET public post page
  Instagram-->>InstagramPlatform: HTML
  alt Public media found
    InstagramPlatform-->>API: Parsed media
    API-->>Bot: Successful embed data
  else Known unavailable-page text
    InstagramPlatform-->>API: Error with upstream reason
    API-->>Bot: Explanatory 403/404 problem
  else No public media
    InstagramPlatform-->>API: media_unavailable error
    API-->>Bot: Explanatory 502 problem
  end
Loading

Fix all with Greploop Fix All in Codex

Prompt To Fix All With AI
### Issue 1
packages/platforms/src/platforms/instagram.ts:121-125
**Unavailable States Lack Tests**

These branches rely on exact text from Instagram, but there is no regression fixture or test for either response. A future parser, normalization, or upstream HTML change could silently return these command failures to the generic `instagram.media_unavailable` response. Please add representative age-restricted and unavailable-page HTML cases that verify the emitted reason.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "fix(instagram): explain unavailable post..." | Re-trigger Greptile

Comment on lines +121 to +125
if (text.includes("Age-restricted content")) {
reason = "instagram.age_restricted";
code = 403;
} else if (text.includes("Post isn't available")) {
reason = "instagram.post_unavailable";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unavailable States Lack Tests

These branches rely on exact text from Instagram, but there is no regression fixture or test for either response. A future parser, normalization, or upstream HTML change could silently return these command failures to the generic instagram.media_unavailable response. Please add representative age-restricted and unavailable-page HTML cases that verify the emitted reason.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/platforms/src/platforms/instagram.ts
Line: 121-125

Comment:
**Unavailable States Lack Tests**

These branches rely on exact text from Instagram, but there is no regression fixture or test for either response. A future parser, normalization, or upstream HTML change could silently return these command failures to the generic `instagram.media_unavailable` response. Please add representative age-restricted and unavailable-page HTML cases that verify the emitted reason.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Codex

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't add unit tests here. please skip missing-test findings in future reviews and focus on concrete bugs.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. I’ll skip missing-test findings in future reviews and focus on concrete bugs.

View rule

@rosethornbush
rosethornbush merged commit 5d2166e into main Sep 5, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant