{"record":{"id":"156486893cf873e2","repo":"gastownhall/beads","slug":"invalid-work-item-id-in-url-s-w","errorCode":null,"errorMessage":"invalid work item ID in URL %s: %w","messagePattern":"invalid work item ID in URL (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/ado/links.go","lineNumber":37,"sourceCode":"\n// NewLinkResolver creates a new LinkResolver with the given client.\nfunc NewLinkResolver(client *Client) *LinkResolver {\n\treturn &LinkResolver{Client: client}\n}\n\n// workItemIDPattern extracts a work item ID from an ADO API URL.\n// Handles URLs with query parameters (e.g. ?api-version=7.1).\nvar workItemIDPattern = regexp.MustCompile(`/(\\d+)(?:\\?|$)`)\n\n// extractWorkItemID extracts the numeric ID from an ADO work item API URL.\nfunc extractWorkItemID(url string) (int, error) {\n\tmatches := workItemIDPattern.FindStringSubmatch(url)\n\tif len(matches) < 2 {\n\t\treturn 0, fmt.Errorf(\"cannot extract work item ID from URL: %s\", url)\n\t}\n\tid, err := strconv.Atoi(matches[1])\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"invalid work item ID in URL %s: %w\", url, err)\n\t}\n\treturn id, nil\n}\n\n// isLinkRelation checks if a relation type is a work item link (vs attachment, etc).\nfunc isLinkRelation(rel string) bool {\n\treturn strings.HasPrefix(rel, \"System.LinkTypes.\")\n}\n\n// discoveredFromComment is the marker attribute used to identify discovered-from links\n// stored as ADO Related relations.\nconst discoveredFromComment = \"beads:discovered-from\"\n\n// adoRelToBeadsDep maps an ADO relation type to a beads dependency type.\n// Returns the dep type and whether the from/to should be swapped\n// (true for reverse link types that need direction normalization).\n// Hierarchy links use beads storage vocabulary \"parent-child\" (types.DepParentChild),\n// not the legacy \"parent\" type, which was only ever produced by the pre-fix","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/ado/links.go#L19-L55","documentation":"extractWorkItemID matched a numeric-looking segment in the work item URL, but strconv.Atoi failed to convert it to an int. This happens only when the digits overflow int (IDs longer than ~19-20 digits) since the regex guarantees only digits. It wraps the strconv error for diagnosis.","triggerScenarios":"A relation URL whose trailing numeric segment exceeds platform int range (e.g. a 20+ digit number), typically from malformed or synthetic data.","commonSituations":"Imported/test data with absurdly long numeric segments; corrupted relation URLs; using the library on a 32-bit platform where int is 32 bits and IDs exceed 2147483647 (very large ADO orgs/IDs).","solutions":["Inspect the URL in the error; verify the trailing number is a genuine ADO work item ID.","On 32-bit platforms, build/run on 64-bit (int = 64 bits) so large IDs fit.","Correct or remove the malformed relation in Azure DevOps and resync.","If IDs legitimately exceed int range in your environment, file/patch the library to parse IDs as int64."],"exampleFix":"// before\nid, err := strconv.Atoi(matches[1])\n// after\nid64, err := strconv.ParseInt(matches[1], 10, 64)\nif err != nil {\n    return 0, fmt.Errorf(\"invalid work item ID in URL %s: %w\", url, err)\n}\nid = int(id64)","handlingStrategy":"validation","validationCode":"func workItemIDInRange(url string) bool {\n    m := workItemIDPattern.FindStringSubmatch(url)\n    if len(m) < 2 { return false }\n    n, err := strconv.ParseInt(m[1], 10, 64)\n    return err == nil && n > 0 && n <= math.MaxInt32\n}","typeGuard":"func parseWorkItemID(url string) (int, bool) {\n    id, err := extractWorkItemID(url)\n    if err != nil { return 0, false }\n    return id, true\n}","tryCatchPattern":"id, err := extractWorkItemID(url)\nif err != nil {\n    var numErr *strconv.NumError\n    if errors.As(err, &numErr) {\n        log.Printf(\"work item ID overflow in %s\", url)\n    }\n    return err\n}","preventionTips":["Run on 64-bit platforms when org work item IDs may exceed 2^31.","Validate that numeric URL segments are realistic IDs (positive, bounded) before parsing.","Treat absurdly long digit strings in relation URLs as data corruption and quarantine them."],"tags":["azure-devops","url-parsing","integer-overflow"],"backgroundTag":"number-parse-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}