Skip to content

Err is nil when filetype is unknown #43

@taylorkline

Description

@taylorkline

Expected behavior:

kind, err := filetype.MatchReader(badReader)

We would expect err != nil, but this is not so.

The documentation appears to contradict itself. In one example, we have:

  kind, unknown := filetype.Match(buf)
  if unknown != nil {
    fmt.Printf("Unknown: %s", unknown)
    return
  }

Yet, in another example, we have:

  // Try to match the file
  fooFile := []byte{0x01, 0x02}
  kind, _ := filetype.Match(fooFile)
  if kind == filetype.Unknown {
    fmt.Println("Unknown file type")
  } else {
    fmt.Printf("File type matched: %s\n", kind.Extension)
  }

I would expect the documentation to be consistent and the error to be populated if we have an unknown filetype.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions