{"record":{"id":"5655542f7ac6732e","repo":"benbjohnson/litestream","slug":"flag-q-must-be-positioned-before-db-path-and-repl","errorCode":null,"errorMessage":"flag %q must be positioned before DB_PATH and REPLICA_URL arguments","messagePattern":"flag %q must be positioned before DB_PATH and REPLICA_URL arguments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream/replicate.go","lineNumber":130,"sourceCode":"\t\t// Initialize config with defaults when using command-line arguments\n\t\tc.Config = DefaultConfig()\n\t\tlogLevel := \"INFO\"\n\t\tif *logLevelFlag != \"\" {\n\t\t\tlogLevel = *logLevelFlag\n\t\t\t// Set env var so initLog sees CLI flag as highest priority\n\t\t\tos.Setenv(\"LOG_LEVEL\", *logLevelFlag)\n\t\t}\n\t\tc.Config.Logging.Level = logLevel\n\t\tinternal.InitLog(os.Stdout, logLevel, \"text\", false)\n\n\t\tdbConfig := &DBConfig{\n\t\t\tPath:                 fs.Arg(0),\n\t\t\tRestoreIfDBNotExists: *restoreIfDBNotExists,\n\t\t}\n\t\tfor _, u := range fs.Args()[1:] {\n\t\t\t// Check if this looks like a flag that was placed after positional arguments\n\t\t\tif strings.HasPrefix(u, \"-\") {\n\t\t\t\treturn fmt.Errorf(\"flag %q must be positioned before DB_PATH and REPLICA_URL arguments\", u)\n\t\t\t}\n\t\t\tsyncInterval := litestream.DefaultSyncInterval\n\t\t\tdbConfig.Replicas = append(dbConfig.Replicas, &ReplicaConfig{\n\t\t\t\tURL: u,\n\t\t\t\tReplicaSettings: ReplicaSettings{\n\t\t\t\t\tSyncInterval: &syncInterval,\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t\tc.Config.DBs = []*DBConfig{dbConfig}\n\t}\n\n\tc.Config.ConfigPath = *configPath\n\n\t// Override config exec command, if specified.\n\tif *execFlag != \"\" {\n\t\tc.Config.Exec = *execFlag\n\t}","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/replicate.go#L112-L148","documentation":"Litestream's `replicate` command accepts DB_PATH and one or more REPLICA_URL arguments as positionals. When a flag (any argument starting with `-`) appears after the first positional argument, Go's flag package stops parsing flags, so it would be silently treated as a replica URL. ParseFlags detects this and rejects it so flags are never misinterpreted as arguments.","triggerScenarios":"Running `litestream replicate db.sqlite -exec \"cmd\" replica_url` or any form where a `-flag` is placed after DB_PATH/REPLICA_URL positionals instead of before them.","commonSituations":"Users copy flag examples and append them at the end of the command line; shell scripts built by concatenating arguments put flags after URLs; muscle memory from tools that accept trailing flags.","solutions":["Move all flags before the DB_PATH argument, e.g. `litestream replicate -exec \"cmd\" db.sqlite s3://bucket/db`","If flags belong to the config file instead, remove them from the CLI and set them in the YAML config","Wrap the replica URL properly — only positional arguments (DB_PATH, REPLICA_URL...) may follow DB_PATH"],"exampleFix":"// before\nlitestream replicate db.sqlite s3://bucket/db -exec \"myapp\"\n// after\nlitestream replicate -exec \"myapp\" db.sqlite s3://bucket/db","handlingStrategy":"validation","validationCode":"// validate CLI ordering before invoking litestream\nconst args = process.argv.slice(2);\nconst firstPos = args.findIndex(a => !a.startsWith('-'));\nconst trailingFlag = firstPos !== -1 && args.slice(firstPos).some(a => a.startsWith('-'));\nif (trailingFlag) throw new Error('all -flags must precede DB_PATH and REPLICA_URL');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always place flags before positional DB_PATH and REPLICA_URL arguments","Build commands from arrays (argv lists) rather than string concatenation","Add a shell wrapper/script that enforces argument order","Consult `litestream replicate -h` for the accepted positional layout"],"tags":["cli","flag-ordering","argument-parsing"],"backgroundTag":"invalid-cli-argument","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"}