tsenart/vegeta · error

error opening %s: %s

Error message

error opening %s: %s

What it means

attack() opens the targets file and optional body file before launching the attack; if `file()` (os.Open-style) fails, the error is wrapped with the offending filename. This almost always means the path does not exist or is not readable.

Source

Thrown at attack.go:139

	if len(opts.resolvers) > 0 {
		res, err := resolver.NewResolver(opts.resolvers)
		if err != nil {
			return err
		}
		net.DefaultResolver = res
	}

	net.DefaultResolver.PreferGo = true

	files := map[string]io.Reader{}
	for _, filename := range []string{opts.targetsf, opts.bodyf} {
		if filename == "" {
			continue
		}
		f, err := file(filename, false)
		if err != nil {
			return fmt.Errorf("error opening %s: %s", filename, err)
		}
		defer f.Close()
		files[filename] = f
	}

	var body []byte
	if bodyf, ok := files[opts.bodyf]; ok {
		if body, err = io.ReadAll(bodyf); err != nil {
			return fmt.Errorf("error reading %s: %s", opts.bodyf, err)
		}
	}

	var (
		tr       vegeta.Targeter
		src      = files[opts.targetsf]
		hdr      = opts.headers.Header
		proxyHdr = opts.proxyHeaders.Header
	)

View on GitHub (pinned to cf58112690)

Solutions

  1. Verify the file exists at the given path (`ls <path>`) and fix the path/typo.
  2. Run vegeta from the directory you expect, or use absolute paths for -targets/-body.
  3. Check file permissions (readable by the user running vegeta); if the path is a directory, point to a regular file.

Example fix

// before
vegeta attack -targets=./tragets.txt
// after
vegeta attack -targets=./targets.txt
Defensive patterns

Strategy: validation

Validate before calling

for _, f := range []string{targetsPath, bodyPath} {
    if f == "" { continue }
    if st, err := os.Stat(f); err != nil || st.IsDir() {
        return fmt.Errorf("input %q is not a readable file", f)
    }
}

Prevention

When it happens

Trigger: Passing `-targets=<path>` or `-body=<path>` pointing to a nonexistent file, a directory, or a file the current user cannot read.

Common situations: Typo in path; running vegeta from a different working directory than assumed; relative path in cron/CI with different cwd; missing permissions in containerized environments.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of tsenart/vegeta@cf58112690 (2026-08-31). Data as JSON: /api/errors/07e454588ff8cc8a. Report an issue: GitHub.