gleam-lang/gleam · error

Unexpected file extension for

Error message

Unexpected file extension for {path:?}

What it means

A repository-hygiene test panic in Gleam's tests (compiler-core/src/tests.rs, `all_files_have_copyright_notice`). The test walks every source file and matches its extension against an allowlist of known extensions before checking for SPDX license headers; an extension not in the allowlist panics with `Unexpected file extension`. This forces new file types to be consciously added to the check.

Solutions

  1. Either remove the file, rename it to an already-allowed extension, or place it where the check excludes it.
  2. If the new file type is legitimate, add an arm for the extension in the match in compiler-core/src/tests.rs (with the appropriate path guard) and ensure it carries the SPDX Apache-2.0 header.
  3. Ensure the file includes both `SPDX-License-Identifier: Apache-2.0` and `SPDX-FileCopyrightText: 20...` lines so the follow-up header check passes.

Example fix

// before (compiler-core/src/tests.rs)
"html" if path.starts_with("../compiler-core/templates/") => (),
_ => panic!("Unexpected file extension for {path:?}"),
// after (compiler-core/src/tests.rs)
"html" if path.starts_with("../compiler-core/templates/") => (),
"json" if path.starts_with("../compiler-core/schemas/") => (),
_ => panic!("Unexpected file extension for {path:?}"),
Defensive patterns

Strategy: validation

Validate before calling

// Before committing, check the extension is handled by the hygiene test
let ext = path.extension().unwrap();
let allowed = ["gleam", "rs", "sh", "toml", "html", /* ... */];
assert!(allowed.contains(&ext.to_str().unwrap()), "unhandled extension {:?} in {}", ext, path);

Prevention

When it happens

Trigger: Committing a file with an extension not covered by the match arms in `all_files_have_copyright_notice` (e.g. `.json`, `.mdx`, `.proto`) anywhere in the repo, then running `cargo test`.

Common situations: Contributors add tooling files (schemas, generated code, new template types outside ../compiler-core/templates/) and the copyright-check test fails in CI with the new path in the message.

Related errors


AI-assisted analysis of gleam-lang/gleam@15b07c7830 (2026-09-14). Data as JSON: /api/errors/224b07ae0f387757. Report an issue: GitHub.

Appendix: source

Thrown at compiler-core/src/tests.rs:170

                "proto" => (),
                "ts" => (),
                "erl" => (),
                "ex" => (),
                "gleam" => (),
                "hrl" => (),
                "js" => (),
                "md" => (),
                "mjs" => (),
                "mts" => (),
                "ps1" => (),
                "rs" => (),
                "sh" => (),
                "toml" => (),

                // HTML templates
                "html" if path.starts_with("../compiler-core/templates/") => (),

                _ => panic!("Unexpected file extension for {path:?}"),
            };

            let text = std::fs::read_to_string(&path).expect("read file");
            if text.contains("SPDX-License-Identifier: Apache-2.0")
                && text.contains("SPDX-FileCopyrightText: 20")
            {
                // Licence information is present
                return None;
            }

            Some(path.to_str().unwrap().to_string())
        })
        .join("\n - ");

    if !paths.is_empty() {
        panic!(
            "Source files missing SPDX licence information!

View on GitHub (pinned to 15b07c7830)