{"record":{"id":"1fbc2a9e2e96ab3d","repo":"siyuan-note/siyuan","slug":"minimax-image-dimensions-must-be-positive-integers","errorCode":null,"errorMessage":"MiniMax image dimensions must be positive integers","messagePattern":"MiniMax image dimensions must be positive integers","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/minimax_image.go","lineNumber":75,"sourceCode":"\treq.Body.Close()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tpayload := map[string]any{\n\t\t\"model\": input.Model, \"prompt\": input.Prompt, \"n\": input.N,\n\t\t\"response_format\": \"url\", \"prompt_optimizer\": true,\n\t}\n\tif input.Size == \"\" || input.Size == \"auto\" {\n\t\tpayload[\"aspect_ratio\"] = \"1:1\"\n\t} else {\n\t\tdimensions := strings.Split(input.Size, \"x\")\n\t\tif len(dimensions) != 2 {\n\t\t\treturn nil, errors.New(\"MiniMax image size must be WIDTHxHEIGHT\")\n\t\t}\n\t\twidth, widthErr := strconv.Atoi(dimensions[0])\n\t\theight, heightErr := strconv.Atoi(dimensions[1])\n\t\tif widthErr != nil || heightErr != nil || width <= 0 || height <= 0 {\n\t\t\treturn nil, errors.New(\"MiniMax image dimensions must be positive integers\")\n\t\t}\n\t\tpayload[\"width\"], payload[\"height\"] = width, height\n\t}\n\tbody, err := json.Marshal(payload)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tconverted := req.Clone(req.Context())\n\tconverted.URL.Path = strings.TrimSuffix(req.URL.Path, \"/images/generations\") + \"/image_generation\"\n\tconverted.URL.RawPath = \"\"\n\tconverted.Body = io.NopCloser(bytes.NewReader(body))\n\tconverted.ContentLength = int64(len(body))\n\tconverted.GetBody = func() (io.ReadCloser, error) { return io.NopCloser(bytes.NewReader(body)), nil }\n\tresp, err := t.base.Do(converted)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif resp.StatusCode < 200 || resp.StatusCode >= 300 {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/minimax_image.go#L57-L93","documentation":"After splitting input.Size on \"x\" and confirming two parts, the transport converts both with strconv.Atoi and requires successful parses and strictly positive values. Non-numeric parts, negatives, or zero are rejected because MiniMax's width/height API fields must be positive integers.","triggerScenarios":"Requesting a MiniMax image with size like \"abcx1024\", \"0x0\", \"-100x100\", \"1024.5x768\" (float string), or a size containing whitespace/units such as \"1024pxx768px\".","commonSituations":"Sizes copied from CSS or px-suffixed values; user-entered config values never sanitized; zero/negative dimensions from broken template defaults; locale-formatted numbers with separators like \"1,024x768\".","solutions":["Pass plain decimal positive integers: \"1024x768\" — no units, decimals, signs, or separators","Sanitize the size string before the call: trim spaces, strip \"px\", parse with strconv.Atoi yourself and clamp to > 0","Validate at config/UI entry time so invalid sizes never reach the request","Fall back to \"\" (default 1:1 aspect ratio) when the value cannot be parsed into positive integers"],"exampleFix":"// before\nsize := \"1024px x 768px\"\n// after\nsize = strings.NewReplacer(\"px\", \"\", \" \", \"\").Replace(size)\nw, err1 := strconv.Atoi(strings.SplitN(size, \"x\", 2)[0])\nh, err2 := strconv.Atoi(strings.SplitN(size, \"x\", 2)[1])\nif err1 != nil || err2 != nil || w <= 0 || h <= 0 {\n    size = \"\" // default 1:1\n}","handlingStrategy":"validation","validationCode":"parts := strings.Split(size, \"x\")\nif len(parts) == 2 {\n    w, e1 := strconv.Atoi(strings.TrimSpace(parts[0]))\n    h, e2 := strconv.Atoi(strings.TrimSpace(parts[1]))\n    if e1 != nil || e2 != nil || w <= 0 || h <= 0 { size = \"\" }\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"must be positive integers\") {\n    return nil, fmt.Errorf(\"reject image size %q: use positive integer WxH like 1024x768\", size)\n}","preventionTips":["Sanitize size inputs: trim whitespace, strip units like px, reject floats and signs","Clamp or reject zero/negative dimensions at UI/config entry time","Use a shared size parser for all AI image providers so formats stay consistent","Default to \"\" (1:1 aspect ratio) whenever parsed dimensions fail validation"],"tags":["go","minimax","image-generation","parameter-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}