FuelLabs/sway · error · anyhow::Error
Loading gas costs from a JSON file is currently not implemen
Error message
Loading gas costs from a JSON file is currently not implemented.
What it means
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.
Source
Thrown at forc-test/src/lib.rs:211
impl GasCostsSource {
pub fn provide_gas_costs(&self) -> Result<GasCostsValues, anyhow::Error> {
match self {
// Values in the `gas_costs_values.json` are taken from the `chain-configuration` repository:
// chain-configuration/upgradelog/ignition/consensus_parameters/<version>.json
// Update these values when there are changes to the on-chain gas costs.
Self::BuiltIn => Ok(serde_json::from_str(include_str!(
"../gas_costs_values.json"
))?),
// TODO: (GAS-COSTS) Fetch actual gas costs from mainnet/testnet and JSON file.
// See: https://github.com/FuelLabs/sway/issues/7472
Self::Mainnet => Err(anyhow::anyhow!(
"Fetching gas costs from mainnet is currently not implemented."
)),
Self::Testnet => Err(anyhow::anyhow!(
"Fetching gas costs from testnet is currently not implemented."
)),
Self::File(_file_path) => Err(anyhow::anyhow!(
"Loading gas costs from a JSON file is currently not implemented."
)),
}
}
}
impl FromStr for GasCostsSource {
type Err = anyhow::Error;
fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
"built-in" => Ok(Self::BuiltIn),
"mainnet" => Ok(Self::Mainnet),
"testnet" => Ok(Self::Testnet),
file_path => Ok(Self::File(file_path.to_string())),
}
}
}View on GitHub (pinned to 47e5e902fa)
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
Example fix
# before forc test --gas-costs ./my_gas_costs.json # after forc test --gas-costs built-in
Defensive patterns
Strategy: validation
Validate before calling
fn parse_gas_costs_source(s: &str) -> anyhow::Result<GasCostsSource> {
match s {
"built-in" => Ok(GasCostsSource::BuiltIn),
other => anyhow::bail!(
"'{other}' would be treated as a file path, which is not implemented; use 'built-in'"
),
}
} Type guard
fn is_implemented(src: &GasCostsSource) -> bool {
matches!(src, GasCostsSource::BuiltIn)
} Try / catch
let values = match source.provide_gas_costs() {
Ok(v) => v,
Err(e) if e.to_string().contains("JSON file") => {
log::warn!("file-based gas costs unsupported; using built-in");
GasCostsSource::BuiltIn.provide_gas_costs()?
}
Err(e) => return Err(e),
}; Prevention
- 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
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- Fetching gas costs from mainnet is currently not implemented
- Fetching gas costs from testnet is currently not implemented
AI-assisted analysis of FuelLabs/sway@47e5e902fa (2026-08-16).
Data as JSON: /api/errors/f660b6368fbea778.
Report an issue: GitHub.