{"record":{"id":"a2c9f02a9d88a222","repo":"AlistGo/alist","slug":"markdown-conversion-failed-w","errorCode":null,"errorMessage":"markdown conversion failed: %w","messagePattern":"markdown conversion failed: %w","errorType":"http","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/handles/down.go","lineNumber":157,"sourceCode":"\t\tcommon.ProxyRange(link, file.GetSize())\n\t}\n\tWriter := &common.WrittenResponseWriter{ResponseWriter: c.Writer}\n\n\t//优先处理md文件\n\tif utils.Ext(file.GetName()) == \"md\" && setting.GetBool(conf.FilterReadMeScripts) {\n\t\tbuf := bytes.NewBuffer(make([]byte, 0, file.GetSize()))\n\t\tw := &common.InterceptResponseWriter{ResponseWriter: Writer, Writer: buf}\n\t\terr = common.Proxy(w, c.Request, link, file)\n\t\tif err == nil && buf.Len() > 0 {\n\t\t\tif c.Writer.Status() < 200 || c.Writer.Status() > 300 {\n\t\t\t\tc.Writer.Write(buf.Bytes())\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tvar html bytes.Buffer\n\t\t\tmd := goldmark.New(goldmark.WithExtensions(extension.GFM))\n\t\t\tif err = md.Convert(buf.Bytes(), &html); err != nil {\n\t\t\t\terr = fmt.Errorf(\"markdown conversion failed: %w\", err)\n\t\t\t} else {\n\t\t\t\tbuf.Reset()\n\t\t\t\terr = bluemonday.UGCPolicy().SanitizeReaderToWriter(&html, buf)\n\t\t\t\tif err == nil {\n\t\t\t\t\tWriter.Header().Set(\"Content-Length\", strconv.FormatInt(int64(buf.Len()), 10))\n\t\t\t\t\tWriter.Header().Set(\"Content-Type\", \"text/html; charset=utf-8\")\n\t\t\t\t\t_, err = utils.CopyWithBuffer(Writer, buf)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\terr = common.Proxy(Writer, c.Request, link, file)\n\t}\n\tif err == nil {\n\t\treturn\n\t}\n\tif Writer.IsWritten() {\n\t\tlog.Errorf(\"%s %s local proxy error: %+v\", c.Request.Method, c.Request.URL.Path, err)","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/server/handles/down.go#L139-L175","documentation":"When serving a markdown file preview, the proxied file bytes are converted to HTML with goldmark (GFM extensions) and sanitized with bluemonday. If goldmark's Convert returns an error, it is wrapped as 'markdown conversion failed: %w'.","triggerScenarios":"Requesting the rendered preview of a .md file whose content triggers a goldmark parse failure — in practice rare, since goldmark is fault-tolerant; realistic causes are writer errors from the bytes.Buffer or memory pressure on very large files.","commonSituations":"Extremely large markdown files exhausting memory; edge-case content hitting a goldmark bug in the pinned version; downstream sanitization issues being confused with this error.","solutions":["Check the wrapped error for the precise goldmark failure","Try downloading the raw file instead of preview to confirm content serves fine","Shrink/split pathological markdown files (huge single-line base64 images are a common culprit)","Upgrade AList to pick up a newer goldmark if a parser bug is confirmed"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if file.GetSize() > maxMarkdownPreviewSize {\n    // serve raw download instead of conversion\n    return common.Proxy(w, c.Request, link, file)\n}","typeGuard":null,"tryCatchPattern":"if err = md.Convert(buf.Bytes(), &html); err != nil {\n    // fall back to serving the raw markdown text rather than a 500\n    w.Header().Set(\"Content-Type\", \"text/plain; charset=utf-8\")\n    _, _ = w.Write(buf.Bytes())\n}","preventionTips":["Cap preview conversion size for .md files","Keep markdown sources free of pathological constructs (huge one-liners, embedded base64 blobs)","Update goldmark along with AList upgrades"],"tags":["go","markdown","preview","goldmark","http-handler"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}