{"record":{"id":"14db2c85deb88d54","repo":"iawia002/lux","slug":"couldn-t-extract-the-media-short-code-from-the-lin","errorCode":null,"errorMessage":"couldn't extract the media short code from the link","messagePattern":"couldn't extract the media short code from the link","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"extractors/instagram/instagram.go","lineNumber":132,"sourceCode":"\t\tfor _, item := range embedResponse.Media.SliderItems.Edges {\n\t\t\tresult = append(result, item.Node.extractMediaURL())\n\t\t}\n\n\t\treturn result, nil\n\t}\n\n\tif embeddedMediaImage != \"\" {\n\t\treturn []string{embeddedMediaImage}, nil\n\t}\n\n\t// If every two methods have failed, then return an error\n\treturn nil, errors.New(\"failed to fetch the post, the page might be \\\"private\\\", or the link is completely wrong\")\n}\n\nfunc extractShortCodeFromLink(link string) (string, error) {\n\tvalues := regexp.MustCompile(`(p|tv|reel|reels\\/videos)\\/([A-Za-z0-9-_]+)`).FindStringSubmatch(link)\n\tif len(values) != 3 {\n\t\treturn \"\", errors.New(\"couldn't extract the media short code from the link\")\n\t}\n\n\treturn values[2], nil\n}\n\ntype extractor struct{}\n\n// New returns a instagram extractor.\nfunc New() extractors.Extractor {\n\treturn &extractor{}\n}\n\n// Extract is the main function to extract the data.\nfunc (e *extractor) Extract(url string, option extractors.Options) ([]*extractors.Data, error) {\n\tu, err := netURL.Parse(url)\n\tif err != nil {\n\t\treturn nil, errors.WithStack(err)\n\t}","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/iawia002/lux/blob/dd00f6d258d80b6684a0b9402d7124e5c18ef42f/extractors/instagram/instagram.go#L114-L150","documentation":"extractShortCodeFromLink pulls the media shortcode from the paths /p/<code>, /tv/<code>, /reel/<code> and /reels/videos/<code>. The error means the link matches none of these shapes, so no Instagram endpoint can be queried. It fails before any network request.","triggerScenarios":"Profile URLs (instagram.com/<user>/); /stories/... links; explore pages; truncated or URL-encoded share links that lost their path.","commonSituations":"Sharing a profile instead of a post; app share-links using path schemes outside the alternation; odd casing or trailing content that breaks the character class.","solutions":["Use the post permalink form https://www.instagram.com/p/<code>/.","For reels use /reel/<code>/; for IGTV /tv/<code>/.","URL-decode and inspect the path portion before passing the link."],"exampleFix":"// before\n$ lux \"https://www.instagram.com/someuser/\"\n// after\n$ lux \"https://www.instagram.com/p/Cx1y2z3AbCd/\"","handlingStrategy":"validation","validationCode":"var shortCodeRe = regexp.MustCompile(`(p|tv|reel|reels/videos)/([A-Za-z0-9-_]+)`)\nif shortCodeRe.FindStringSubmatch(link) == nil {\n\treturn fmt.Errorf(\"not an instagram post link (need /p|/tv|/reel/<code>): %s\", link)\n}","typeGuard":"func isInstagramPostLink(link string) bool {\n\treturn regexp.MustCompile(`(p|tv|reel|reels/videos)/([A-Za-z0-9-_]+)`).MatchString(link)\n}","tryCatchPattern":null,"preventionTips":["Validate the path shape before enqueueing Instagram URLs","Normalize share links to /p/<code>/ permalink form","Reject profile and stories links early with a clear message"],"tags":["instagram","url-validation","share-link"],"backgroundTag":null,"analyzedSha":"dd00f6d258d80b6684a0b9402d7124e5c18ef42f","analyzedAt":"2026-08-15T16:57:31.080Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}