{"record":{"id":"15ebc1376a07096d","repo":"siyuan-note/siyuan","slug":"errinvalidmode","errorCode":"ErrInvalidMode","errorMessage":"invalid HEIF conversion mode","messagePattern":"invalid HEIF conversion mode","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/heif/convert.go","lineNumber":54,"sourceCode":"\tpreviewQuality   = 90\n\tthumbnailQuality = 85\n\tMaxInputBytes    = 32 * 1024 * 1024\n\tmaxDimension     = 65535\n\tdesktopMaxPixels = 50_000_000\n\tmobileMaxPixels  = 12_500_000\n\t// 解码层仅接受至多 10-bit 4:2:0、无透明通道的单 slice 图像；这里按解码面、CTU 表、\n\t// NRGBA 和一次合并变换预留每像素 16 字节，再单独预留源文件、RBSP 副本与 JPEG 输出。\n\tworkingBytesPerPixel = 16\n\tdesktopWorkingBudget = 960 * 1024 * 1024\n\tmobileWorkingBudget  = 320 * 1024 * 1024\n\tdesktopOutputReserve = 96 * 1024 * 1024\n\tmobileOutputReserve  = 32 * 1024 * 1024\n)\n\nvar (\n\tErrInputTooLarge = errors.New(\"HEIF image exceeds the input size limit\")\n\tErrImageTooLarge = errors.New(\"HEIF image exceeds the dimension limit\")\n\tErrInvalidMode   = errors.New(\"invalid HEIF conversion mode\")\n\n\tconversionSlots = make(chan struct{}, 1)\n\tmaxPixels       = platformMaxPixels()\n)\n\nfunc platformMaxPixels() int {\n\tif runtime.GOOS == \"android\" || runtime.GOOS == \"ios\" {\n\t\treturn pixelsWithinBudget(mobileWorkingBudget, mobileOutputReserve, mobileMaxPixels)\n\t}\n\treturn pixelsWithinBudget(desktopWorkingBudget, desktopOutputReserve, desktopMaxPixels)\n}\n\nfunc ReadFileLimited(path string, maxBytes int64) ([]byte, error) {\n\tif maxBytes <= 0 {\n\t\treturn nil, ErrInputTooLarge\n\t}\n\tfile, err := os.Open(path)\n\tif err != nil {","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/heif/convert.go#L36-L72","documentation":"ErrInvalidMode means Options.Mode passed to GetOrCreate is neither ModePreview (\"preview\") nor ModeThumbnail (\"thumb\"). GetOrCreate validates all options (mode, BoxID for encrypted input) before spending the single conversion slot or decoding, so invalid options fail fast and cheaply. The zero-value Options{} has an empty Mode, so forgetting to set Mode always triggers this.","triggerScenarios":"Calling GetOrCreate with Options{} (zero value) or any Mode other than ModePreview/ModeThumbnail, as guarded at cache.go:89 and covered by TestGetOrCreateValidatesOptionsBeforeDecode.","commonSituations":"Constructing Options without initializing Mode (empty string), a typo'd custom mode constant, refactoring that renamed modes without updating a caller.","solutions":["Set options.Mode explicitly to heif.ModePreview or heif.ModeThumbnail","Use the typed constants (heif.Mode) instead of raw strings to get compile-time safety","Validate options in your own wrapper before calling GetOrCreate"],"exampleFix":"// before\nresult, err := heif.GetOrCreate(ctx, data, heif.Options{})\n// after\nresult, err := heif.GetOrCreate(ctx, data, heif.Options{Mode: heif.ModePreview})","handlingStrategy":"validation","validationCode":"if opts.Mode != heif.ModePreview && opts.Mode != heif.ModeThumbnail {\n\treturn fmt.Errorf(\"mode must be preview or thumb\")\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n\tif errors.Is(err, heif.ErrInvalidMode) {\n\t\t// fix Options construction — Mode was empty or invalid\n\t}\n\treturn err\n}","preventionTips":["Always set Options.Mode using the typed heif.Mode constants","Never rely on the zero value of Options","Validate encrypted options (BoxID) together with Mode before calling"],"tags":["heif","configuration","validation"],"backgroundTag":"invalid-enum-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"}