github-linguist / github-linguist/linguist

Confusing (for Noobs) error message when used to analyse Single File which is not committed into Git Repo

Open
#7,162 3 comments 0 reactions 0 assignees View on GitHub
Bug
Dominant language
Ruby
Stars
13.7k
Forks
5.4k
Avg merge
1d 15h
Merged PRs (30d)
17

Description

https://github.com/github-linguist/linguist#single-file says you can do e.g. `github-linguist README.md`.

This works, of course - but only if the file is actually committed into a Git repository, and otherwise fails with a (to me) obscure internal error.

This confused the hell out of me, and it took me a fair bit of trial and error to narrow this down to being root cause related to the file is actually committed into a Git repository.

In an ideal world, it might be cool if Linguist also just worked for uncommitted files?

Unless this is a deliberate design decision, and not just an oversight, or regression? If that's the case, a clear error message would be neat.

Here are the fully reproducible technical details of what actually currently happens:

```
$ bin/github-linguist README.md
README.md: 228 lines (167 sloc)
type: Text
mime type: text/markdown
language: Markdown

$ cp README.md README2.md

$ bin/github-linguist README2.md
/home/vorburger/git/github.com/github-linguist/linguist/lib/linguist/source/rugged.rb:65:in `to_buffer': wrong argument type nil (expected String) (TypeError)

Rugged::Blob.to_buffer(@rugged, blob_id, max_size)
^^^^^^^^^^^^^^^^^^^^^^^^^^
from /home/vorburger/git/github.com/github-linguist/linguist/lib/linguist/source/rugged.rb:65:in `load_blob'
from /home/vorburger/git/github.com/github-linguist/linguist/lib/linguist/lazy_blob.rb:117:in `load_blob!'
from /home/vorburger/git/github.com/github-linguist/linguist/lib/linguist/lazy_blob.rb:91:in `data'
from /home/vorburger/git/github.com/github-linguist/linguist/lib/linguist/blob_helper.rb:127:in `binary?'
from /home/vorburger/git/github.com/github-linguist/linguist/lib/linguist/blob_helper.rb:155:in `text?'
from bin/github-linguist:112:in `github_linguist'
from bin/github-linguist:155:in `'
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.