{"record":{"id":"9dccdfe9179ad023","repo":"FuelLabs/sway","slug":"invalid-revert-code-for-test-a-revert-code-m","errorCode":null,"errorMessage":"Invalid revert code for test \"{}\".\nA revert code must be a string containing a \"u64\", e.g.: \"42\".\nThe invalid revert code was: {}.","messagePattern":"Invalid revert code for test \"(.+?)\"\\.\nA revert code must be a string containing a \"u64\", e\\.g\\.: \"42\"\\.\nThe invalid revert code was: (.+?)\\.","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"forc-pkg/src/pkg.rs","lineNumber":2071,"sourceCode":"}\n\nimpl PkgEntryKind {\n    /// Returns `Some` if the `PkgEntryKind` is `Test`.\n    pub fn test(&self) -> Option<&PkgTestEntry> {\n        match self {\n            PkgEntryKind::Test(test) => Some(test),\n            _ => None,\n        }\n    }\n}\n\nimpl PkgTestEntry {\n    fn from_decl(decl_ref: &DeclRefFunction, engines: &Engines) -> Result<Self> {\n        fn get_invalid_revert_code_error_msg(\n            test_function_name: &Ident,\n            should_revert_arg: &AttributeArg,\n        ) -> String {\n            format!(\"Invalid revert code for test \\\"{}\\\".\\nA revert code must be a string containing a \\\"u64\\\", e.g.: \\\"42\\\".\\nThe invalid revert code was: {}.\",\n                test_function_name,\n                should_revert_arg.value.as_ref().expect(\"`get_string_opt` returned either a value or an error, which means that the invalid value must exist\").span().as_str(),\n            )\n        }\n\n        let span = decl_ref.span();\n        let test_function_decl = engines.de().get_function(decl_ref);\n\n        let Some(test_attr) = test_function_decl.attributes.test() else {\n            unreachable!(\"`test_function_decl` is guaranteed to be a test function and it must have a `#[test]` attribute\");\n        };\n\n        let pass_condition = match test_attr\n            .args\n            .iter()\n            // Last \"should_revert\" argument wins ;-)\n            .rfind(|arg| arg.is_test_should_revert())\n        {","sourceCodeStart":2053,"sourceCodeEnd":2089,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc-pkg/src/pkg.rs#L2053-L2089","documentation":"While collecting tests for a package, PkgTestEntry::from_decl reads the last `should_revert` argument of a `#[test]` attribute. The value must be a string literal parseable as a decimal u64 (`val.parse::<u64>()`), or omitted entirely (bare `#[test(should_revert)]`). This anyhow error names the offending test and echoes the invalid value when the string fails to parse (or when get_string_opt reports the argument is not a string).","triggerScenarios":"`#[test(should_revert = \"0x2a\")]` (hex not accepted by u64::from_str); `should_revert = \"\"` or `should_revert = \"42a\"`; passing a non-string literal as the revert code; duplicated should_revert args where the last one is malformed (last one wins).","commonSituations":"Porting tests from syntax/docs that show hex revert codes; copy-pasting contract error codes (often hex) into should_revert; typos in the numeric string; using a bare u64 literal instead of a quoted string.","solutions":["Use a decimal u64 in a string: `#[test(should_revert = \"42\")]`.","If any revert is acceptable, drop the value: `#[test(should_revert)]`.","Convert hex codes to decimal before embedding (0x2a -> \"42\")."],"exampleFix":"// before\n#[test(should_revert = \"0x2a\")]\nfn test_revert() { revert(42); }\n// after\n#[test(should_revert = \"42\")]\nfn test_revert() { revert(42); }","handlingStrategy":"validation","validationCode":"# CI lint: every should_revert value must be a decimal u64 string\ngrep -RnoE '#\\[test\\(should_revert *= *\"[^\"]*\"\\)\\]' --include='*.sw' . \\\n  | sed -E 's/.*\"([^\"]*)\"\\)$/\\1/' | grep -qvE '^[0-9]+$' \\\n  && { echo 'non-u64 should_revert value found' >&2; exit 1; } || true","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use bare `#[test(should_revert)]` unless the exact code matters.","Convert hex revert codes to decimal strings before writing the attribute.","Keep should_revert values quoted — u64::from_str only accepts decimal digits."],"tags":["sway","forc","forc-pkg","test","should-revert","attribute","u64"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}