{"record":{"id":"84ba72139ad85818","repo":"grafana/k6","slug":"s-already-exists-use-the-force-flag-to-overw","errorCode":null,"errorMessage":"%s already exists. Use the `--force` flag to overwrite it","messagePattern":"(.+?) already exists\\. Use the `--force` flag to overwrite it","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/new.go","lineNumber":44,"sourceCode":"\tflags.SortFlags = false\n\tflags.BoolVarP(&c.overwriteFiles, \"force\", \"f\", false, \"overwrite existing files\")\n\tflags.StringVar(&c.templateType, \"template\", \"minimal\", \"template type (choices: minimal, protocol, browser) or relative/absolute path to a custom template file\") //nolint:lll\n\tflags.StringVar(&c.projectID, \"project-id\", \"\", \"specify the Grafana Cloud project ID for the test\")\n\treturn flags\n}\n\nfunc (c *newScriptCmd) run(_ *cobra.Command, args []string) (err error) {\n\ttarget := defaultNewScriptName\n\tif len(args) > 0 {\n\t\ttarget = args[0]\n\t}\n\n\tfileExists, err := fsext.Exists(c.gs.FS, target)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif fileExists && !c.overwriteFiles {\n\t\treturn fmt.Errorf(\"%s already exists. Use the `--force` flag to overwrite it\", target)\n\t}\n\n\t// Initialize template manager and validate template before creating any files\n\ttm, err := templates.NewTemplateManager(c.gs.FS)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error initializing template manager: %w\", err)\n\t}\n\n\ttmpl, err := tm.GetTemplate(c.templateType)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error retrieving template: %w\", err)\n\t}\n\n\t// Prepare template arguments\n\targsStruct := templates.TemplateArgs{\n\t\tScriptName: target,\n\t\tProjectID:  c.projectID,\n\t}","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/cmd/new.go#L26-L62","documentation":"Guard in the 'k6 new' command's run: the target script file already exists on disk and --force/-f was not given, so k6 refuses to overwrite it.","triggerScenarios":"Thrown at internal/cmd/new.go:44 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-run with 'k6 new --force' (or -f) to overwrite the existing file","Choose a different target filename as the positional argument","Move or delete the existing file first"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}