{"record":{"id":"f660b6368fbea778","repo":"FuelLabs/sway","slug":"loading-gas-costs-from-a-json-file-is-currently-no","errorCode":null,"errorMessage":"Loading gas costs from a JSON file is currently not implemented.","messagePattern":"Loading gas costs from a JSON file is currently not implemented\\.","errorType":"console","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"forc-test/src/lib.rs","lineNumber":211,"sourceCode":"\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),\n            \"mainnet\" => Ok(Self::Mainnet),\n            \"testnet\" => Ok(Self::Testnet),\n            file_path => Ok(Self::File(file_path.to_string())),\n        }\n    }\n}","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc-test/src/lib.rs#L193-L229","documentation":"GasCostsSource::FromStr treats any string that is not \"built-in\"/\"mainnet\"/\"testnet\" as a file path (Self::File), but provide_gas_costs() immediately errors for File(_) because loading gas costs from JSON is unimplemented (sway#7472). Note the path is never even opened — the variant matches on `Self::File(_file_path)` and discards it.","triggerScenarios":"`forc test --gas-costs path/to/gas_costs.json`, or GasCostsSource::from_str(\"my.json\") then provide_gas_costs(). Any unrecognized token becomes File and hits the stub.","commonSituations":"Developers trying to supply custom/chain-specific gas cost values, or who typo an intended keyword (e.g. \"builtin\" without hyphen) and are surprised it is silently interpreted as a file path that then errors.","solutions":["Use `--gas-costs built-in` until file loading is implemented","If you control the version of gas_costs_values.json you need, rebuild forc with an updated bundled JSON rather than passing a file","Upgrade forc once sway#7472 lands the File arm"],"exampleFix":"# before\nforc test --gas-costs ./my_gas_costs.json\n\n# after\nforc test --gas-costs built-in","handlingStrategy":"validation","validationCode":"fn parse_gas_costs_source(s: &str) -> anyhow::Result<GasCostsSource> {\n    match s {\n        \"built-in\" => Ok(GasCostsSource::BuiltIn),\n        other => anyhow::bail!(\n            \"'{other}' would be treated as a file path, which is not implemented; use 'built-in'\"\n        ),\n    }\n}","typeGuard":"fn is_implemented(src: &GasCostsSource) -> bool {\n    matches!(src, GasCostsSource::BuiltIn)\n}","tryCatchPattern":"let values = match source.provide_gas_costs() {\n    Ok(v) => v,\n    Err(e) if e.to_string().contains(\"JSON file\") => {\n        log::warn!(\"file-based gas costs unsupported; using built-in\");\n        GasCostsSource::BuiltIn.provide_gas_costs()?\n    }\n    Err(e) => return Err(e),\n};","preventionTips":["Remember FromStr is greedy: every unrecognized token becomes File(...), so validate against the three known keywords explicitly","Keep custom chain-parameters work pinned to forks that implement the File arm"],"tags":["forc-test","gas-costs","not-implemented","file-path"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}