{"record":{"id":"711d813ead5cd666","repo":"FuelLabs/sway","slug":"fetching-gas-costs-from-mainnet-is-currently-not-i","errorCode":null,"errorMessage":"Fetching gas costs from mainnet is currently not implemented.","messagePattern":"Fetching gas costs from mainnet is currently not implemented\\.","errorType":"console","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"forc-test/src/lib.rs","lineNumber":205,"sourceCode":"    #[default]\n    BuiltIn,\n    Mainnet,\n    Testnet,\n    File(String),\n}\n\nimpl GasCostsSource {\n    pub fn provide_gas_costs(&self) -> Result<GasCostsValues, anyhow::Error> {\n        match self {\n            // Values in the `gas_costs_values.json` are taken from the `chain-configuration` repository:\n            //      chain-configuration/upgradelog/ignition/consensus_parameters/<version>.json\n            // Update these values when there are changes to the on-chain gas costs.\n            Self::BuiltIn => Ok(serde_json::from_str(include_str!(\n                \"../gas_costs_values.json\"\n            ))?),\n            // TODO: (GAS-COSTS) Fetch actual gas costs from mainnet/testnet and JSON file.\n            //       See: https://github.com/FuelLabs/sway/issues/7472\n            Self::Mainnet => Err(anyhow::anyhow!(\n                \"Fetching gas costs from mainnet is currently not implemented.\"\n            )),\n            Self::Testnet => Err(anyhow::anyhow!(\n                \"Fetching gas costs from testnet is currently not implemented.\"\n            )),\n            Self::File(_file_path) => Err(anyhow::anyhow!(\n                \"Loading gas costs from a JSON file is currently not implemented.\"\n            )),\n        }\n    }\n}\n\nimpl FromStr for GasCostsSource {\n    type Err = anyhow::Error;\n\n    fn from_str(value: &str) -> Result<Self, Self::Err> {\n        match value {\n            \"built-in\" => Ok(Self::BuiltIn),","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc-test/src/lib.rs#L187-L223","documentation":"forc-test's GasCostsSource::provide_gas_costs() only implements the BuiltIn variant, which deserializes the bundled gas_costs_values.json. The Mainnet variant is an explicit stub (tracked in FuelLabs/sway#7472) that always returns this anyhow error. It exists so the CLI flag --gas-costs mainnet parses (FromStr maps \"mainnet\" to Self::Mainnet) but fails loudly instead of silently using wrong costs.","triggerScenarios":"Running `forc test --gas-costs mainnet`, or programmatically GasCostsSource::from_str(\"mainnet\")?.provide_gas_costs(). The FromStr parse succeeds; the error is deferred until provide_gas_costs() is called during test setup for coverage/gas profiling.","commonSituations":"A developer wants gas cost coverage results that match mainnet consensus parameters instead of the bundled snapshot, or copies a command from docs/CI that uses a value supported by a different forc version. Older/newer forc releases differ in which gas-cost sources are wired up.","solutions":["Use the default built-in costs: drop the flag or pass `forc test --gas-costs built-in` (values track chain-configuration repo's ignition consensus parameters)","Upgrade forc to a release where mainnet fetching landed (check sway issue #7472 status)","As a library user, match on GasCostsSource::BuiltIn before calling provide_gas_costs and reject Mainnet early with your own message"],"exampleFix":"# before\nforc test --gas-costs mainnet\n\n# after\nforc test --gas-costs built-in","handlingStrategy":"validation","validationCode":"// Rust caller of forc_test::GasCostsSource\nuse forc_test::GasCostsSource;\nuse std::str::FromStr;\n\nfn gas_costs(src: &str) -> anyhow::Result<()> {\n    let source = GasCostsSource::from_str(src)?;\n    if source != GasCostsSource::BuiltIn {\n        anyhow::bail!(\"gas cost source '{src}' is not implemented in this forc version; use 'built-in'\");\n    }\n    let values = source.provide_gas_costs()?;\n    Ok(())\n}","typeGuard":"fn is_supported_gas_costs_source(s: &str) -> bool {\n    s == \"built-in\"\n}","tryCatchPattern":"match GasCostsSource::from_str(src)?.provide_gas_costs() {\n    Ok(v) => { /* ... */ }\n    Err(e) if e.to_string().contains(\"not implemented\") => {\n        eprintln!(\"gas-cost source unsupported, falling back to built-in\");\n        GasCostsSource::BuiltIn.provide_gas_costs()?;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Pin CI and docs to --gas-costs built-in until mainnet/testnet/file support ships (sway#7472)","Treat any non-keyword value as a file path: FromStr silently maps typos like 'builtin' to File, which also errors"],"tags":["forc-test","gas-costs","not-implemented","cli"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}