siyuan-note/siyuan · error

custom emoji file must not be empty

Error message

custom emoji file must not be empty

What it means

Returned by normalizeCustomEmojiData when the input byte slice is zero-length. This means the upload/url-download produced an empty body: a 200 with empty content, a zero-byte file, or a LimitReader that read nothing.

Source

Thrown at kernel/api/system.go:355

	}
	defer response.Body.Close()
	if response.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("download custom emoji failed with status %d", response.StatusCode)
	}
	if response.ContentLength > maxCustomEmojiSize {
		return nil, fmt.Errorf("custom emoji file is too large")
	}

	data, err := io.ReadAll(io.LimitReader(response.Body, maxCustomEmojiSize+1))
	if err != nil {
		return nil, fmt.Errorf("read custom emoji response failed: %w", err)
	}
	return data, nil
}

func normalizeCustomEmojiData(data []byte) (normalized []byte, ext string, err error) {
	if len(data) == 0 {
		return nil, "", fmt.Errorf("custom emoji file must not be empty")
	}

	raster := true
	switch http.DetectContentType(data) {
	case "image/png":
		ext = ".png"
	case "image/jpeg":
		ext = ".jpg"
	case "image/gif":
		ext = ".gif"
	case "image/webp":
		ext = ".webp"
	default:
		raster = false
	}
	if raster {
		config, _, decodeErr := image.DecodeConfig(bytes.NewReader(data))
		if decodeErr != nil || config.Width < 1 || config.Height < 1 || config.Width > 16384 || config.Height > 16384 ||

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Check the source file size locally (ls -l / stat) before uploading.
  2. If using url, curl -I the URL and confirm Content-Length is non-zero and matches an image.
  3. Re-export or re-download the original asset and retry.

Example fix

// before
// uploading a 0-byte file -> 'custom emoji file must not be empty'

// after: guard before the API call
if fi, e := os.Stat(path); e != nil || fi.Size() == 0 {
    return errors.New("emoji file is missing or empty")
}
Defensive patterns

Strategy: validation

Validate before calling

if len(data) == 0 { return errors.New("emoji data is empty before upload") }

Prevention

When it happens

Trigger: POST /api/system/addCustomEmoji with an empty file, or a url whose server returns 200 with a zero-length body (e.g. a CDN edge returning an empty object, or a misconfigured object store).

Common situations: User selected a 0-byte file by mistake; the file was truncated during a prior sync; the source URL is an empty S3 object; git-LFS pointer file not yet resolved.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/1f2e796c6f41c4ae. Report an issue: GitHub.