{"record":{"id":"392d9632b421532c","repo":"swc-project/swc","slug":"failed-to-read-file","errorCode":null,"errorMessage":"failed to read file","messagePattern":"failed to read file","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_testing/src/babel_like.rs","lineNumber":122,"sourceCode":"                let mut done = false;\n                for factory in &mut factories {\n                    if let Some(built) = factory(&builder, &name, options.clone()) {\n                        pass = Box::new((pass, built));\n                        done = true;\n                        break;\n                    }\n                }\n\n                if !done {\n                    panic!(\"Unknown plugin: {name}\");\n                }\n            }\n\n            pass = Box::new((pass, hygiene(), fixer(Some(&comments))));\n\n            // Run pass\n\n            let src = read_to_string(self.input).expect(\"failed to read file\");\n            let src = if output_path.is_none() && !compare_stdout {\n                format!(\n                    \"it('should work', async function () {{\n                    {src}\n                }})\",\n                )\n            } else {\n                src\n            };\n            let fm = cm.new_source_file(\n                swc_common::FileName::Real(self.input.to_path_buf()).into(),\n                src,\n            );\n\n            let mut errors = Vec::new();\n            let input_program = parse_file_as_program(\n                &fm,\n                self.syntax,","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_testing/src/babel_like.rs#L104-L140","documentation":"The Babel-compatibility test harness (crates/swc_ecma_transforms_testing/src/babel_like.rs) drives fixture tests that read the input JS file from disk before transforming it. `read_to_string(self.input).expect(\"failed to read file\")` panics when the fixture file recorded for the test cannot be read: it does not exist, permissions block it, or it is not valid UTF-8.","triggerScenarios":"Registering a Babel-like fixture whose input path has a typo or missing file; running tests from a tree where fixtures were not checked out (sparse checkout, .gitignore rules, submodule not initialized); a non-UTF-8 fixture; or file permissions/lock issues on the fixture.","commonSituations":"Adding fixtures modeled after Babel test cases (input.js + output.js pairs) and mistyping the path; CI environments where fixture files are missing; moving fixture directories without updating the test registration.","solutions":["Verify the input path exists: `ls` the fixture directory the test points to and correct the path used when the test was declared.","If submodules or generated fixtures are involved, run `git submodule update --init --recursive` and regenerate fixtures before `cargo test`.","Ensure the file is UTF-8 encoded and readable by the test user.","For new fixtures, follow the crate convention (input/output files next to each other) so the harness finds them."],"exampleFix":"// before\ntest_fixture(\n    Syntax::default(),\n    tr,\n    &tests_dir.join(\"does-not-exist/input.js\"), // wrong path\n    ...,\n)\n\n// after\ntest_fixture(\n    Syntax::default(),\n    tr,\n    &tests_dir.join(\"issue1234/input.js\"), // matches file on disk\n    ...,\n)","handlingStrategy":"validation","validationCode":"// Before registering a fixture test, assert both files exist and are UTF-8.\nfn fixture_ok(input: &std::path::Path, output: Option<&std::path::Path>) -> bool {\n    std::fs::read(input).is_ok()\n        && output.map_or(true, |o| o.exists())\n        && std::fs::read_to_string(input)\n            .map(|s| s.is_ascii() || true) // UTF-8 checked by read_to_string\n            .is_ok()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add a tiny debug_assert or precondition that the fixture input path exists before calling the harness.","Keep fixture file naming consistent with the crate's conventions so registration paths never drift.","Initialize submodules and regenerate fixtures before running the suite."],"tags":["test-harness","fixture","file-not-found","filesystem","swc"],"backgroundTag":"fixture-file-not-found","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}