gofiber/fiber · critical

favicon: read limited

Error message

favicon: read limited: %w

What it means

Returned by favicon.readLimited when io.ReadAll fails while reading the favicon file (capped at MaxBytes+1 via LimitReader). The wrapped %w is the underlying reader error — typically an I/O failure on the open file or embedded FS. Note: New() panics on this error at middleware construction time, so it surfaces as a startup panic, not a per-request error.

Solutions

  1. Check the file is readable end-to-end: `cat cfg.File > /dev/null` on the host/container.
  2. If using embed.FS, rebuild the binary so the embedded bytes are intact.
  3. Validate the file at startup and fail with a clear message instead of panicking.
  4. Ensure the path/permissions are correct in the deployment environment.

Example fix

// before
app.Use(favicon.New(favicon.Config{File: "/srv/favicon.ico"}))
// after
f, err := os.ReadFile("/srv/favicon.ico")
if err != nil { log.Fatal(err) }
app.Use(favicon.New(favicon.Config{Data: f}))
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.ReadFile(cfg.File); err != nil { log.Fatal(err) }

Prevention

When it happens

Trigger: Constructing favicon.New with a Config.File whose content cannot be read — disk read error, file truncated mid-read, broken embed.FS, NFS hiccup, or a reader that errors after partial data. readLimited is called once during New(), so the panic happens at app startup.

Common situations: Bad file path that opens but reads incompletely, a corrupt embedded asset, a network-mounted filesystem with intermittent errors, or a container where the favicon file is a broken symlink/mount at read time.

Related errors


AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11). Data as JSON: /api/errors/87a1ae22cab8acd5. Report an issue: GitHub.

Appendix: source

Thrown at middleware/favicon/favicon.go:107

		}

		// Serve cached favicon
		if iconLen > 0 {
			c.Set(fiber.HeaderContentLength, iconLenHeader)
			c.Set(fiber.HeaderContentType, hType)
			c.Set(fiber.HeaderCacheControl, cfg.CacheControl)
			return c.Status(fiber.StatusOK).Send(iconData)
		}

		return c.SendStatus(fiber.StatusNoContent)
	}
}

func readLimited(reader io.Reader, maxBytes int64) ([]byte, error) {
	limit := maxBytes + 1
	data, err := io.ReadAll(io.LimitReader(reader, limit))
	if err != nil {
		return nil, fmt.Errorf("favicon: read limited: %w", err)
	}
	if int64(len(data)) > maxBytes {
		return nil, fmt.Errorf("favicon: file size exceeds max bytes %d", maxBytes)
	}
	return data, nil
}

View on GitHub (pinned to a105acad6c)