{"record":{"id":"0166c337dae85c04","repo":"moodle/moodle","slug":"invalidwidthexception-invalid-border-part-width-s","errorCode":null,"errorMessage":"InvalidWidthException (invalid border part width: %s)","messagePattern":"InvalidWidthException \\(invalid border part width: (.+?)\\)","errorType":"validation","errorClass":"InvalidWidthException","httpStatus":null,"severity":"error","filePath":"public/lib/openspout/src/Common/Entity/Style/BorderPart.php","lineNumber":62,"sourceCode":"     *\n     * @throws InvalidNameException\n     * @throws InvalidStyleException\n     * @throws InvalidWidthException\n     */\n    public function __construct(\n        string $name,\n        string $color = Color::BLACK,\n        string $width = Border::WIDTH_MEDIUM,\n        string $style = Border::STYLE_SOLID\n    ) {\n        if (!\\in_array($name, self::allowedNames, true)) {\n            throw new InvalidNameException($name);\n        }\n        if (!\\in_array($style, self::allowedStyles, true)) {\n            throw new InvalidStyleException($style);\n        }\n        if (!\\in_array($width, self::allowedWidths, true)) {\n            throw new InvalidWidthException($width);\n        }\n\n        $this->name = $name;\n        $this->color = $color;\n        $this->width = $width;\n        $this->style = $style;\n    }\n\n    public function getName(): string\n    {\n        return $this->name;\n    }\n\n    public function getStyle(): string\n    {\n        return $this->style;\n    }\n","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/lib/openspout/src/Common/Entity/Style/BorderPart.php#L44-L80","documentation":"BorderPart validates that the width is one of the allowed widths (Border::WIDTH_THIN, _MEDIUM, _THICK) and throws InvalidWidthException otherwise; arbitrary widths would not map to valid XLSX border weights.","triggerScenarios":"new BorderPart(Border::LEFT, Color::BLACK, '2px', ...) or any $width string not in BorderPart::$allowedWidths when building a border part.","commonSituations":"Passing pixel or point values ('1px','0.5pt') instead of the named constants; config-driven styling where widths come from user input; migrating code from another spreadsheet library that uses numeric widths.","solutions":["Use Border::WIDTH_THIN, Border::WIDTH_MEDIUM or Border::WIDTH_THICK constants only.","Clamp/map desired visual widths to the nearest allowed constant (thin/medium/thick).","Validate config-supplied width strings against BorderPart::$allowedWidths before construction."],"exampleFix":"// before\n$part = new BorderPart(Border::LEFT, Color::BLACK, '2px');\n// after\n$part = new BorderPart(Border::LEFT, Color::BLACK, Border::WIDTH_THICK);","handlingStrategy":"validation","validationCode":"// assert in_array($width, BorderPart::$allowedWidths, true) before constructing\nif (!in_array($width, \\OpenSpout\\Common\\Entity\\Style\\BorderPart::$allowedWidths, true)) {\n    throw new InvalidArgumentException('Unsupported border width: '.$width);\n}","typeGuard":"function isValidBorderWidth(?string $width): bool {\n    return $width !== null && in_array($width, \\OpenSpout\\Common\\Entity\\Style\\BorderPart::$allowedWidths, true);\n}","tryCatchPattern":"try {\n    $part = new BorderPart($name, $color, $width, $style);\n} catch (OpenSpout\\Common\\Exception\\Style\\InvalidWidthException $e) {\n    // clamp to nearest of thin/medium/thick and retry\n}","preventionTips":["Only use Border::WIDTH_THIN/MEDIUM/THICK constants.","Convert pixel/point widths to the nearest allowed constant in a mapping helper.","Validate user/config-supplied widths before constructing style objects.","Document that openspout supports only three symbolic border widths."],"tags":["openspout","php","xlsx","style"],"backgroundTag":"value-out-of-range","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}