{"record":{"id":"392751731dca4753","repo":"unionlabs/union","slug":"invalid-gas-price-string","errorCode":null,"errorMessage":"Invalid gas price string","messagePattern":"Invalid gas price string","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"patches/@cosmjs__stargate.patch","lineNumber":81,"sourceCode":"-    toString() {\n-        return this.amount.toString() + this.denom;\n+  constructor(amount, denom) {\n+    this.amount = amount\n+    this.denom = denom\n+  }\n+  /**\n+   * Parses a gas price formatted as `<amount><denom>`, e.g. `GasPrice.fromString(\"0.012utoken\")`.\n+   *\n+   * The denom must match the Cosmos SDK 0.42 pattern (https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/types/coin.go#L599-L601).\n+   * See `GasPrice` in @cosmjs/stargate for a more generic matcher.\n+   *\n+   * Separators are not yet supported.\n+   */\n+  static fromString(gasPrice) {\n+    // Use Decimal.fromUserInput and checkDenom for detailed checks and helpful error messages\n+    const matchResult = gasPrice.match(/^([0-9.]+)([a-zA-Z][a-zA-Z0-9/:._-]*)$/)\n+    if (!matchResult) {\n+      throw new Error(\"Invalid gas price string\")\n     }\n+    const [_, amount, denom] = matchResult\n+    checkDenom(denom)\n+    const fractionalDigits = 18\n+    const decimalAmount = math_1.Decimal.fromUserInput(amount, fractionalDigits)\n+    return new GasPrice(decimalAmount, denom)\n+  }\n+  /**\n+   * Returns a string representation of this gas price, e.g. \"0.025uatom\".\n+   * This can be used as an input to `GasPrice.fromString`.\n+   */\n+  toString() {\n+    return this.amount.toString() + this.denom\n+  }\n }\n-exports.GasPrice = GasPrice;\n+exports.GasPrice = GasPrice\n function calculateFee(gasLimit, gasPrice) {","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/unionlabs/union/blob/031785bb6dc6b957c624e62bc64c184409c97d7b/patches/@cosmjs__stargate.patch#L63-L99","documentation":"Thrown by the patched GasPrice.fromString in @cosmjs/stargate when the input does not match ^([0-9.]+)([a-zA-Z][a-zA-Z0-9/:._-]*)$ — i.e. it is not <decimal amount immediately followed by denom starting with a letter>. The regex rejects separators, signs, and scientific notation before checkDenom ever runs.","triggerScenarios":"Gas price strings like \"0.5 uatom\" (space), \"1,5utoken\" (comma separator), \"-0.1uatom\" (negative), \"1e-6uatom\" (scientific notation), \"uatom\" or \"0.025\" alone, or a denom starting with a digit or slash.","commonSituations":"User-entered gas prices from forms pasted with whitespace; locale-formatted decimals using commas; config files storing gas price with units separated; negative or exponent notation from calculators.","solutions":["Normalize the string: trim whitespace and remove thousands/decimal separators, e.g. gasPrice.trim().replace(\",\", \".\") then strip any space between amount and denom","Use the plain <amount><denom> form: \"0.025uatom\"","Validate against the pattern before passing it into client creation"],"exampleFix":"// before\nconst gasPrice = GasPrice.fromString(\"0.025 uatom\") // throws\n\n// after\nconst gasPrice = GasPrice.fromString(\"0.025uatom\") // amount and denom joined, no separators","handlingStrategy":"validation","validationCode":"const GAS_PRICE_PATTERN = /^([0-9.]+)([a-zA-Z][a-zA-Z0-9/:._-]*)$/\nconst normalizeGasPrice = (input: string) =>\n  input.trim().replace(/\\s+/g, \"\").replace(/,/g, \".\") // \"0.025 uatom\" -> \"0.025uatom\"\n\nconst normalized = normalizeGasPrice(userInput)\nif (!GAS_PRICE_PATTERN.test(normalized)) {\n  throw new Error(`Gas price must be <amount><denom>, got: ${userInput}`)\n}\nconst gasPrice = GasPrice.fromString(normalized)","typeGuard":"const isGasPriceString = (s: string): s is `${number}${string}` =>\n  /^[0-9.]+[a-zA-Z][a-zA-Z0-9/:._-]*$/.test(s)","tryCatchPattern":"try {\n  const gasPrice = GasPrice.fromString(raw)\n} catch (error) {\n  if ((error as Error).message === \"Invalid gas price string\") {\n    // strip whitespace/separators, reject negatives & scientific notation, then retry once\n  }\n  throw error\n}","preventionTips":["Normalize user/config input (trim, no separators, no exponent notation) before parsing","Test gas-price parsing in unit tests for comma/space/negative cases","Prefer typed gas price objects over string round-trips where the API allows"],"tags":["cosmos","gas-price","validation","patch"],"backgroundTag":null,"analyzedSha":"031785bb6dc6b957c624e62bc64c184409c97d7b","analyzedAt":"2026-08-16T06:24:09.996Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}