golang/go · error

missing source file(s)

Error message

missing source file(s)

What it means

Thrown by 'go tool cover' parseFlags when -mode is set but no Go source file arguments are supplied (flag.NArg() == 0). Instrumentation mode requires at least one input .go file to annotate; with zero files there is nothing to do.

Source

Thrown at src/cmd/cover/cover.go:172

			cmode = coverage.CtrModeSet
		case "count":
			counterStmt = incCounterStmt
			cmode = coverage.CtrModeCount
		case "atomic":
			counterStmt = atomicCounterStmt
			cmode = coverage.CtrModeAtomic
		case "regonly":
			counterStmt = nil
			cmode = coverage.CtrModeRegOnly
		case "testmain":
			counterStmt = nil
			cmode = coverage.CtrModeTestMain
		default:
			return fmt.Errorf("unknown -mode %v", *mode)
		}

		if flag.NArg() == 0 {
			return fmt.Errorf("missing source file(s)")
		} else {
			if *pkgcfg != "" {
				if *output != "" {
					return fmt.Errorf("please use '-outfilelist' flag instead of '-o'")
				}
				var err error
				if outputfiles, err = readOutFileList(*outfilelist); err != nil {
					return err
				}
				covervarsoutfile = outputfiles[0]
				outputfiles = outputfiles[1:]
				numInputs := len(flag.Args())
				numOutputs := len(outputfiles)
				if numOutputs != numInputs {
					return fmt.Errorf("number of output files (%d) not equal to number of input files (%d)", numOutputs, numInputs)
				}
				if err := readPackageConfig(*pkgcfg); err != nil {
					return err

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Append the .go file(s) or a glob that resolves to at least one file
  2. Verify your file list/glob is non-empty before invoking the tool
  3. Use the -pkgcfg workflow when instrumenting a whole package via the go command

Example fix

# before
go tool cover -mode=set
# after
go tool cover -mode=set main.go lib.go
Defensive patterns

Strategy: validation

Validate before calling

# Ensure at least one input file before invoking in -mode
files=(src/*.go)
if [ ${#files[@]} -eq 0 ]; then echo "no source files" >&2; exit 2; fi
go tool cover -mode=set "${files[@]}"

Prevention

When it happens

Trigger: `go tool cover -mode=set` with no trailing file arguments.

Common situations: Glob in a shell script expanding to nothing. Forgetting to pass the package's files. Running the tool manually to test a flag without providing input.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/632b138a372b7d4a. Report an issue: GitHub.