{"record":{"id":"7427ec71ab09df9f","repo":"benbjohnson/litestream","slug":"invalid-target-size-w","errorCode":null,"errorMessage":"invalid target size: %w","messagePattern":"invalid target size: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/populate.go","lineNumber":49,"sourceCode":"\tfs.StringVar(&c.DB, \"db\", \"\", \"Database path (required)\")\n\tfs.StringVar(&c.TargetSize, \"target-size\", \"100MB\", \"Target database size (e.g., 1GB, 500MB)\")\n\tfs.IntVar(&c.RowSize, \"row-size\", 1024, \"Average row size in bytes\")\n\tfs.IntVar(&c.BatchSize, \"batch-size\", 1000, \"Rows per transaction\")\n\tfs.IntVar(&c.TableCount, \"table-count\", 1, \"Number of tables to create\")\n\tfs.Float64Var(&c.IndexRatio, \"index-ratio\", 0.2, \"Percentage of columns to index (0.0-1.0)\")\n\tfs.IntVar(&c.PageSize, \"page-size\", 4096, \"SQLite page size in bytes\")\n\tfs.Usage = c.Usage\n\tif err := fs.Parse(args); err != nil {\n\t\treturn err\n\t}\n\n\tif c.DB == \"\" {\n\t\treturn fmt.Errorf(\"database path required\")\n\t}\n\n\ttargetBytes, err := parseSize(c.TargetSize)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid target size: %w\", err)\n\t}\n\n\tslog.Info(\"Starting database population\",\n\t\t\"db\", c.DB,\n\t\t\"target_size\", c.TargetSize,\n\t\t\"row_size\", c.RowSize,\n\t\t\"batch_size\", c.BatchSize,\n\t\t\"table_count\", c.TableCount,\n\t\t\"page_size\", c.PageSize,\n\t)\n\n\tif err := c.populateDatabase(ctx, targetBytes); err != nil {\n\t\treturn fmt.Errorf(\"populate database: %w\", err)\n\t}\n\n\tslog.Info(\"Database population complete\", \"db\", c.DB)\n\treturn nil\n}","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/populate.go#L31-L67","documentation":"populate parses the -target-size flag (default \"100MB\") with parseSize, which expects a size string like \"1GB\", \"500MB\". If the string cannot be parsed into a byte count, Run wraps the parse error as \"invalid target size\". This validates user-supplied size notation before any database work starts.","triggerScenarios":"Passing `-target-size` values parseSize cannot handle: plain numbers without a unit suffix, misspelled units (\"1gb\" if case-sensitive, \"1 GiB\", \"1G B\"), negative values, or empty strings.","commonSituations":"Users writing \"1GiB\" or \"1 Gb\" instead of the accepted format; locale-formatted numbers (\"1,5GB\"); shell quoting issues splitting the value from the flag.","solutions":["Use a plain value with a supported unit suffix, e.g. `-target-size 1GB` or `-target-size 500MB` (match the format shown in the flag help).","Remove thousands separators, spaces, or non-standard suffixes (GiB/KiB) from the value.","Check the parseSize implementation in this repo for the exact accepted units and case sensitivity if unsure."],"exampleFix":"// before\nlitestream-test populate -db ./test.db -target-size 1GiB\n// error: invalid target size\n\n// after\nlitestream-test populate -db ./test.db -target-size 1GB","handlingStrategy":"validation","validationCode":"const m = /^\\d+(KB|MB|GB)$/.exec(targetSize);\nif (!m) throw new Error(`invalid target size \"${targetSize}\": use forms like 100MB or 1GB`);","typeGuard":"function isValidSize(s) {\n  return /^\\d+(KB|MB|GB)$/.test(s);\n}","tryCatchPattern":"try {\n  await run(\"litestream-test\", [\"populate\", \"-db\", dbPath, \"-target-size\", targetSize]);\n} catch (e) {\n  if (String(e).includes(\"invalid target size\")) {\n    console.error(`\"${targetSize}\" is not parseable; use <number><KB|MB|GB>, e.g. 500MB`);\n  }\n  throw e;\n}","preventionTips":["Use unit suffixes exactly as documented (KB/MB/GB), no spaces or GiB-style suffixes.","Avoid locale-formatted numbers (commas, decimal commas) in size strings.","Quote the whole -target-size value in shell to prevent splitting."],"tags":["cli","argument-parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}