{"record":{"id":"e8597d6228cb0539","repo":"iOfficeAI/OfficeCLI","slug":"picture-shape-name-must-be-non-negative-got-v","errorCode":null,"errorMessage":"Picture/shape {name} must be non-negative (got '{value}').","messagePattern":"Picture/shape (.+?) must be non-negative \\(got '(.+?)'\\)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.Drawing.cs","lineNumber":1410,"sourceCode":"            ParseAnchorOrigin(properties.GetValueOrDefault(\"y\", defY) ?? defY, \"y\"),\n            ParseAnchorDimension(widthRaw, \"width\"),\n            ParseAnchorDimension(heightRaw, \"height\")\n        );\n    }\n\n    /// <summary>\n    /// Parse an anchor origin value (x/y) that is either a plain non-negative\n    /// integer cell index (\"0\", \"5\") or a unit-qualified offset (\"2cm\", \"1in\",\n    /// \"72pt\"). Unit-qualified values are converted to a cell index using the\n    /// same approximate EMU/column and EMU/row factors as ParseAnchorDimension.\n    /// CONSISTENCY(ole-width-units): symmetric with width/height units.\n    /// </summary>\n    private static int ParseAnchorOrigin(string value, string name)\n    {\n        if (int.TryParse(value, out var plainInt))\n        {\n            if (plainInt < 0)\n                throw new ArgumentException($\"Picture/shape {name} must be non-negative (got '{value}').\");\n            return plainInt;\n        }\n\n        long emu;\n        try\n        {\n            emu = OfficeCli.Core.EmuConverter.ParseEmu(value);\n        }\n        catch\n        {\n            throw new ArgumentException($\"Expected a non-negative cell index or a unit-qualified offset (e.g. '2cm', '1in') for {name}, got '{value}'.\");\n        }\n        if (emu < 0)\n            throw new ArgumentException($\"Picture/shape {name} must be non-negative (got '{value}').\");\n\n        const long emuPerColApprox = 609600;\n        const long emuPerRowApprox = 190500;\n        if (name == \"y\")","sourceCodeStart":1392,"sourceCodeEnd":1428,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Drawing.cs#L1392-L1428","documentation":"Thrown by ParseAnchorOrigin when a plain-integer x/y anchor origin parses successfully but is negative. Anchor origins (x, y) are 0-based cell indices for the FROM marker of a twoCell anchor; a negative index would write an invalid <xdr:col>/<xdr:row> that Excel rejects. The guard rejects the bare-integer form before any unit conversion is attempted.","triggerScenarios":"Passing x=-5 or y=-1 as a bare integer on an anchor that routes through ParseAnchorOrigin. The unit-qualified negative case (e.g. '-1in') is a separate code path that throws at line 1424 with the same message text.","commonSituations":"Negative offsets copied from a coordinate system with a different origin (e.g. screen-space top-left with negative y for 'up'); AI assistants defaulting unknown x/y to -1; programmatic subtraction underflowing past zero.","solutions":["Use a non-negative cell index for x and y: x=0, y=2.","If you need a sub-cell offset within the FROM cell, use a oneCell/absolute anchor with EMU units instead of a negative twoCell origin.","Clamp the computed value to >= 0 before passing.","Switch to a cell-reference anchor= like 'B2' which is always non-negative by construction."],"exampleFix":"// before\nshape anchor=twoCell x=-2 y=0\n// after\nshape anchor=twoCell x=0 y=0","handlingStrategy":"validation","validationCode":"bool IsValidOriginInt(string value)\n    => int.TryParse(value, out var i) && i >= 0;","typeGuard":"static bool IsNonNegativeCellIndex(string s)\n    => int.TryParse(s, out var i) && i >= 0;","tryCatchPattern":"try { ParseAnchorOrigin(value, \"x\"); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"must be non-negative\"))\n{\n    // clamp to 0 or surface a user error\n}","preventionTips":["Use a non-negative integer cell index for x/y origins.","Clamp computed origins to >= 0.","Use a cell-reference anchor= for guaranteed-non-negative positioning.","Validate the sign before passing if sourcing from computed offsets."],"tags":["excel","drawing","anchor","origin","validation","cell-index"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}