github-linguist/linguist · error · ArgumentError
invalid type: #{@type}
Error message
invalid type: #{@type} What it means
Language#initialize converts the `type` attribute to a symbol and validates it against the fixed set returned by get_types: :data, :markup, :programming, :prose (language.rb:305-308). Anything else (or a string that doesn't sym-match one of those four) raises ArgumentError before the language is ever registered. A nil/omitted type passes the check — the error is specifically about a present-but-invalid value. It fires at require time for languages.yml entries and immediately for programmatic Language.new/create calls.
Source
Thrown at lib/linguist/language.rb:270
#
# Returns an Array of Languages.
def self.colors
@colors ||= all.select(&:color).sort_by { |lang| lang.name.downcase }
end
# Internal: Initialize a new Language
#
# attributes - A hash of attributes
def initialize(attributes = {})
# @name is required
@name = attributes[:name] || raise(ArgumentError, "missing name")
@fs_name = attributes[:fs_name]
# Set type
@type = attributes[:type] ? attributes[:type].to_sym : nil
if @type && !get_types.include?(@type)
raise ArgumentError, "invalid type: #{@type}"
end
@color = attributes[:color]
# Set aliases
@aliases = [default_alias] + (attributes[:aliases] || [])
@tm_scope = attributes[:tm_scope] || 'none'
@ace_mode = attributes[:ace_mode]
@codemirror_mode = attributes[:codemirror_mode]
@codemirror_mime_type = attributes[:codemirror_mime_type]
@wrap = attributes[:wrap] || false
# Set the language_id
@language_id = attributes[:language_id]
# Set extensions or default to [].
@extensions = attributes[:extensions] || []View on GitHub (pinned to b45dbe9b28)
Solutions
- Change the type in languages.yml to one of the four valid values: data, markup, programming, or prose.
- Check for stray characters — quotes, commas, trailing spaces — around the type value in YAML.
- If you genuinely need a new category, that is a library change (extend get_types) — not a per-entry fix; raise it with maintainers instead.
- For programmatic use, validate with %i[data markup programming prose].include?(type.to_sym) before construction.
Example fix
# before (lib/linguist/languages.yml) TOML: type: data-format # after TOML: type: data
Defensive patterns
Strategy: validation
Validate before calling
VALID_TYPES = %i[data markup programming prose].freeze
unless attributes[:type].nil? || VALID_TYPES.include?(attributes[:type].to_sym)
raise ArgumentError, "type must be one of #{VALID_TYPES.join(', ')}"
end Type guard
def valid_language_type?(t) %i[data markup programming prose].include?(t.to_sym) end
Try / catch
begin Linguist::Language.create(attributes) rescue ArgumentError => e raise if e.message !~ /invalid type/ attributes[:type] = :programming # or prompt the author for the right category end
Prevention
- Treat type as a closed enum: data, markup, programming, prose — nothing else.
- Beware YAML typos: trailing commas/quotes or whitespace make to_sym produce an unknown symbol.
- When copying entries between versions of languages.yml, re-check the type value against the current enum.
When it happens
Trigger: 1) A languages.yml entry with `type: script`, `type: mark-up`, or a trailing character ("programming,") — YAML hands the string over, to_sym produces an unknown symbol. 2) Passing type: :functional in Language.create. 3) Copying an entry from an older/newer version of the file whose allowed type set differs. The message interpolates the symbol, e.g. "invalid type: functional".
Common situations: Contributors guessing at type names ('script', 'markup language', 'data-format'); YAML typos and invisible whitespace in the type value; tooling that generates languages.yml with a type vocabulary from a different schema version.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Extension is missing a '.': #{extension.inspect}
- Duplicate language name: #{language.name}
- Duplicate language name: #{language.fs_name}
- Duplicate alias: #{name}
- read_index is deprecated
AI-assisted analysis of github-linguist/linguist@b45dbe9b28 (2026-08-21).
Data as JSON: /api/errors/c58cc6e63fac24bd.
Report an issue: GitHub.