{"record":{"id":"224b07ae0f387757","repo":"gleam-lang/gleam","slug":"unexpected-file-extension-for-path","errorCode":null,"errorMessage":"Unexpected file extension for {path:?}","messagePattern":"Unexpected file extension for (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/tests.rs","lineNumber":170,"sourceCode":"                \"proto\" => (),\n                \"ts\" => (),\n                \"erl\" => (),\n                \"ex\" => (),\n                \"gleam\" => (),\n                \"hrl\" => (),\n                \"js\" => (),\n                \"md\" => (),\n                \"mjs\" => (),\n                \"mts\" => (),\n                \"ps1\" => (),\n                \"rs\" => (),\n                \"sh\" => (),\n                \"toml\" => (),\n\n                // HTML templates\n                \"html\" if path.starts_with(\"../compiler-core/templates/\") => (),\n\n                _ => panic!(\"Unexpected file extension for {path:?}\"),\n            };\n\n            let text = std::fs::read_to_string(&path).expect(\"read file\");\n            if text.contains(\"SPDX-License-Identifier: Apache-2.0\")\n                && text.contains(\"SPDX-FileCopyrightText: 20\")\n            {\n                // Licence information is present\n                return None;\n            }\n\n            Some(path.to_str().unwrap().to_string())\n        })\n        .join(\"\\n - \");\n\n    if !paths.is_empty() {\n        panic!(\n            \"Source files missing SPDX licence information!\n","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/tests.rs#L152-L188","documentation":"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.","triggerScenarios":"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`.","commonSituations":"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.","solutions":["Either remove the file, rename it to an already-allowed extension, or place it where the check excludes it.","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.","Ensure the file includes both `SPDX-License-Identifier: Apache-2.0` and `SPDX-FileCopyrightText: 20...` lines so the follow-up header check passes."],"exampleFix":"// before (compiler-core/src/tests.rs)\n\"html\" if path.starts_with(\"../compiler-core/templates/\") => (),\n_ => panic!(\"Unexpected file extension for {path:?}\"),\n// after (compiler-core/src/tests.rs)\n\"html\" if path.starts_with(\"../compiler-core/templates/\") => (),\n\"json\" if path.starts_with(\"../compiler-core/schemas/\") => (),\n_ => panic!(\"Unexpected file extension for {path:?}\"),","handlingStrategy":"validation","validationCode":"// Before committing, check the extension is handled by the hygiene test\nlet ext = path.extension().unwrap();\nlet allowed = [\"gleam\", \"rs\", \"sh\", \"toml\", \"html\", /* ... */];\nassert!(allowed.contains(&ext.to_str().unwrap()), \"unhandled extension {:?} in {}\", ext, path);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `cargo test -p gleam-core all_files_have_copyright_notice` before opening a PR that adds new files.","When introducing a new file type, update the match arms and add the SPDX header to the file in the same commit.","Keep generated/vendor files in paths the test excludes, or extend the exclusion guards deliberately."],"tags":["rust","ci","license-check","repository-hygiene"],"backgroundTag":"unsupported-enum-value","analyzedSha":"15b07c783065c92bb016b1b74ed0995a5259850f","analyzedAt":"2026-09-14T11:14:59.388Z","contentChangedAt":"2026-09-14T11:14:59.388Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}