grafana/k6 · error
already exists. Use the `--force` flag to overwrite it
Error message
%s already exists. Use the `--force` flag to overwrite it
What it means
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.
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
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/cmd/new.go:44 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/84ba72139ad85818.
Report an issue: GitHub.
Appendix: source
Thrown at internal/cmd/new.go:44
flags.SortFlags = false
flags.BoolVarP(&c.overwriteFiles, "force", "f", false, "overwrite existing files")
flags.StringVar(&c.templateType, "template", "minimal", "template type (choices: minimal, protocol, browser) or relative/absolute path to a custom template file") //nolint:lll
flags.StringVar(&c.projectID, "project-id", "", "specify the Grafana Cloud project ID for the test")
return flags
}
func (c *newScriptCmd) run(_ *cobra.Command, args []string) (err error) {
target := defaultNewScriptName
if len(args) > 0 {
target = args[0]
}
fileExists, err := fsext.Exists(c.gs.FS, target)
if err != nil {
return err
}
if fileExists && !c.overwriteFiles {
return fmt.Errorf("%s already exists. Use the `--force` flag to overwrite it", target)
}
// Initialize template manager and validate template before creating any files
tm, err := templates.NewTemplateManager(c.gs.FS)
if err != nil {
return fmt.Errorf("error initializing template manager: %w", err)
}
tmpl, err := tm.GetTemplate(c.templateType)
if err != nil {
return fmt.Errorf("error retrieving template: %w", err)
}
// Prepare template arguments
argsStruct := templates.TemplateArgs{
ScriptName: target,
ProjectID: c.projectID,
}View on GitHub (pinned to 01ffac6f24)