Skip to content

"unknown image format" does not say which file, which makes it expensive to diagnose in a build #1953

Description

@glennmichael123

A frontend build in stacksjs/stacks fails with:

Build failed: ts-images: unknown image format (no matching magic bytes)

The diagnosis is correct. The input really was not an image: 14 tracked PNGs in that repo had their 0D bytes stripped by a * text=auto gitattributes rule, so the signature reads 89 50 4E 47 0A 1A 0A instead of 89 50 4E 47 0D 0A 1A 0A (stacksjs/stacks#2433).

The problem is that the message names no file. The build processes many images, the error surfaces once, and nothing indicates which input was rejected. Working back to the file meant checking magic bytes across every tracked image in the repository, which is a lot of work for something the library already knew at the moment it threw.

Suggestion

Include the path, and ideally the bytes actually seen:

ts-images: unknown image format for public/images/avatars/avatar-1.png
  expected a known signature, read 89 50 4e 47 0a 1a 0a 00

The first eight bytes are enough to make a corrupted-header case obvious on sight, which is exactly the case that is hardest to guess at. Where the caller supplies a buffer rather than a path, naming the index or whatever handle it has still beats nothing.

Version: ts-images@0.2.13.

Happy to send the PR if you point me at where the error is raised.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions