{"record":{"id":"6f94c3fb841af722","repo":"anomalyco/sst","slug":"invalid-size-size","errorCode":null,"errorMessage":"Invalid size ${size}","messagePattern":"Invalid size (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"platform/src/components/size.ts","lineNumber":14,"sourceCode":"export type Size = `${number} ${\"MB\" | \"GB\"}`;\nexport type SizeGbTb = `${number} ${\"GB\" | \"TB\"}`;\n\nexport function toMBs(size: Size | SizeGbTb) {\n  const [count, unit] = size.split(\" \");\n  const countNum = parseFloat(count);\n  if (unit === \"MB\") {\n    return countNum;\n  } else if (unit === \"GB\") {\n    return countNum * 1024;\n  } else if (unit === \"TB\") {\n    return countNum * 1024 * 1024;\n  }\n  throw new Error(`Invalid size ${size}`);\n}\n\nexport function toGBs(size: Size | SizeGbTb) {\n  const [count, unit] = size.split(\" \");\n  const countNum = parseFloat(count);\n  if (unit === \"MB\") {\n    return countNum / 1024;\n  } else if (unit === \"GB\") {\n    return countNum;\n  } else if (unit === \"TB\") {\n    return countNum * 1024;\n  }\n  throw new Error(`Invalid size ${size}`);\n}\n","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/components/size.ts#L1-L29","documentation":"toMBs converts a size string like '512 MB', '2 GB', or '1 TB' into megabytes. It throws this error when the unit suffix after the space is not one of MB, GB, or TB. TypeScript's template-literal types (Size/SizeGbTb) normally prevent this at compile time, but a value cast or read at runtime (e.g. from config or env) bypasses the type and hits this guard.","triggerScenarios":"Calling toMBs (directly or via memory/containerDefinitions/createTaskDefinition) with a string whose unit is not exactly 'MB', 'GB', or 'TB' — e.g. '512MB' (no space), '512 mb' (lowercase), '0.5 GiB', or a number without a unit.","commonSituations":"Specifying an ECS task/container memory in sst.config.ts with the wrong format: missing space, lowercase unit, MiB/GiB binary units, or a memory value interpolated from a non-typed source like an environment variable or JSON config.","solutions":["Format the size as '<number> <UNIT>' with a space and an uppercase unit from MB/GB/TB, e.g. '512 MB' instead of '512MB' or '512 mb'.","Convert binary units: use '512 MB' not '512 MiB', or precompute the MB value yourself.","If the value comes from a variable, cast it to Size only after validating the format with a regex like /^\\d+(\\.\\d+)? (MB|GB|TB)$/.","Call toGBs instead if you actually want gigabytes — but note it accepts the same units, so fix the string either way."],"exampleFix":"// before\nmemory: process.env.TASK_MEMORY as Size // e.g. \"512MB\"\n// after\nconst mem = process.env.TASK_MEMORY ?? \"512 MB\";\nif (!/^\\d+(\\.\\d+)? (MB|GB|TB)$/.test(mem)) throw new Error(`bad memory size: ${mem}`);\nmemory: mem as Size","handlingStrategy":"validation","validationCode":"const SIZE_RE = /^\\d+(\\.\\d+)? (MB|GB|TB)$/;\nif (!SIZE_RE.test(String(size))) throw new Error(`size must match '<n> MB|GB|TB', got: ${size}`);","typeGuard":"function isSize(v: unknown): v is `${number} ${\"MB\" | \"GB\" | \"TB\"}` {\n  return typeof v === \"string\" && /^\\d+(\\.\\d+)? (MB|GB|TB)$/.test(v);\n}","tryCatchPattern":"let mb: number;\ntry { mb = toMBs(size); } catch (e) {\n  throw new Error(`Invalid memory size \"${size}\" — use e.g. \"512 MB\" or \"2 GB\"`, { cause: e });\n}","preventionTips":["Always include a single space between the number and unit: '512 MB', never '512MB'.","Use only uppercase MB/GB/TB; avoid MiB/GiB binary units.","Never cast unvalidated strings (env vars, JSON) to Size without a regex check.","Centralize size parsing behind a helper that validates once."],"tags":["configuration","validation","typescript","ecs"],"backgroundTag":"invalid-size-unit","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}