{"record":{"id":"467f7b2730227ab3","repo":"FuelLabs/sway","slug":"missing-span-for-test","errorCode":null,"errorMessage":"Missing span for test \\\"{}\\\".","messagePattern":"Missing span for test \\\\\"(.+?)\\\\\"\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"forc-pkg/src/pkg.rs","lineNumber":2114,"sourceCode":"                            .map_err(|_| {\n                                anyhow!(get_invalid_revert_code_error_msg(\n                                    &test_function_decl.name,\n                                    should_revert_arg\n                                ))\n                            })?,\n                    ),\n                    Err(_) => bail!(get_invalid_revert_code_error_msg(\n                        &test_function_decl.name,\n                        should_revert_arg\n                    )),\n                }\n            }\n            None => TestPassCondition::ShouldNotRevert,\n        };\n\n        let file_path =\n            Arc::new(engines.se().get_path(span.source_id().ok_or_else(|| {\n                anyhow!(\"Missing span for test \\\"{}\\\".\", test_function_decl.name)\n            })?));\n        Ok(Self {\n            pass_condition,\n            span,\n            file_path,\n        })\n    }\n}\n\n/// The suffix that helps identify the file which contains the hash of the binary file created when\n/// scripts are built_package.\npub const SWAY_BIN_HASH_SUFFIX: &str = \"-bin-hash\";\n\n/// The suffix that helps identify the file which contains the root hash of the binary file created\n/// when predicates are built_package.\npub const SWAY_BIN_ROOT_SUFFIX: &str = \"-bin-root\";\n\n/// Selects the build profile from all available build profiles in the workspace using build_opts.","sourceCodeStart":2096,"sourceCodeEnd":2132,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc-pkg/src/pkg.rs#L2096-L2132","documentation":"While collecting a test's metadata, forc resolves the test's file path via engines.se().get_path(span.source_id()). If the stored span for the #[test] declaration carries no source id, there is no file to attribute the test to and forc bails with this message. It is an internal invariant failure: declarations parsed from real files always carry source ids.","triggerScenarios":"Programmatic or LSP compilation where the declaration's span was synthesized without a source id (macro-generated or injected AST nodes), or tooling that constructs engines without registering the source file before parsing.","commonSituations":"Custom tools built on sway compiler APIs that fabricate declarations without file info; rarely a compiler refactor bug - then usually accompanied by other span-related errors.","solutions":["Write the tests in a real .sw file compiled from disk instead of generating declarations without source info","If you use the compiler APIs directly, register every file with the SourceEngine (get_source_id/new_source) before parsing","Update forc/sway to the latest patch release in case this is already fixed","If it reproduces with stock `forc test`, open an issue with a minimal project"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match pkg::CompiledTests::from_manifest(...) {\n    Ok(tests) => run(tests),\n    Err(e) if e.to_string().contains(\"Missing span for test\") => {\n        // generated declarations without source info: warn and skip instead of aborting\n        log::warn!(\"skipping test discovery, tests lack spans: {e}\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Register every source file with the SourceEngine before parsing so spans carry source ids","Avoid fabricating test declarations without file information","Keep forc and sway compiler crates version-matched in tooling"],"tags":["sway","testing","spans","lsp","internal"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}