nats-io/nats-server · error

must specify [-c, --config] option to check configuration fi

Error message

must specify [-c, --config] option to check configuration file syntax

What it means

NATS server flag processing produces this when -check_config (check-config behavior) is requested but no configuration file was supplied via -c/--config. There is no file to parse, so syntax checking cannot proceed and ProcessConfigFile/flag handling returns this error.

Source

Thrown at server/opts.go:6403

				return nil, err
			}
			if cerr, ok := err.(*processConfigErr); !ok || len(cerr.Errors()) != 0 {
				return nil, err
			}
			// If we get here we only have warnings and can still continue
			fmt.Fprint(os.Stderr, err)
		} else if opts.CheckConfig {
			// Report configuration file syntax test was successful and exit.
			return opts, nil
		}

		// Call this again to override config file options with options from command line.
		// Note: We don't need to check error here since if there was an error, it would
		// have been caught the first time this function was called (after setting up the
		// flags).
		fs.Parse(args)
	} else if opts.CheckConfig {
		return nil, fmt.Errorf("must specify [-c, --config] option to check configuration file syntax")
	}

	// Special handling of some flags
	var (
		flagErr     error
		tlsDisabled bool
		tlsOverride bool
	)
	fs.Visit(func(f *flag.Flag) {
		// short-circuit if an error was encountered
		if flagErr != nil {
			return
		}
		if strings.HasPrefix(f.Name, "tls") {
			if f.Name == "tls" {
				if !opts.TLS {
					// User has specified "-tls=false", we need to disable TLS
					opts.TLSConfig = nil

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Run `nats-server -c /path/to/nats.conf -check_config` so there is a file to validate.
  2. If the server legitimately runs with no config file, skip the check step.
  3. Verify flag ordering/spelling: -c must precede or follow with its file argument in the same command.

Example fix

// before
nats-server --check_config
// after
nats-server -c nats.conf --check_config
Defensive patterns

Strategy: validation

Validate before calling

// In CI: ensure a config file is supplied when checking syntax
if [ -z "$CONFIG_FILE" ]; then echo "-c CONFIG required with -check_config"; exit 1; fi
nats-server -c "$CONFIG_FILE" --check_config

Type guard

null

Try / catch

if err := validateFlags(); err != nil {
    if strings.Contains(err.Error(), "must specify [-c, --config]") {
        fmt.Fprintln(os.Stderr, "Usage: nats-server -c <file> --check_config")
        os.Exit(2)
    }
}

Prevention

When it happens

Trigger: Running `nats-server -check_config` (or setting CheckConfig) without also passing `-c <file>`.

Common situations: CI syntax-validation scripts that forgot the config flag, docs examples where -c was dropped, or checking a server that was intentionally started without any config file.

Related errors


AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02). Data as JSON: /api/errors/41c2a082501307b6. Report an issue: GitHub.