hyperledger/fabric · error

no server specified

Error message

no server specified

What it means

The discovery CLI's peers command requires a discovery server (a peer's discovery service endpoint) to send the request to. If the --server flag was not provided or was an empty string, Execute returns this error before any network activity. Discovery is a client-initiated query; there is no default peer to ask.

Source

Thrown at discovery/cmd/peers.go:56

func (pc *PeerCmd) SetServer(server *string) {
	pc.server = server
}

// SetChannel sets the channel of the PeerCmd
func (pc *PeerCmd) SetChannel(channel *string) {
	pc.channel = channel
}

// Execute executes the command
func (pc *PeerCmd) Execute(conf common.Config) error {
	channel := ""

	if pc.channel != nil {
		channel = *pc.channel
	}

	if pc.server == nil || *pc.server == "" {
		return errors.New("no server specified")
	}

	server := *pc.server

	req := discovery.NewRequest()
	if channel != "" {
		req = req.OfChannel(channel)
		req = req.AddPeersQuery()
	} else {
		req = req.AddLocalPeersQuery()
	}
	res, err := pc.stub.Send(server, conf, req)
	if err != nil {
		return err
	}
	return pc.parser.ParseResponse(channel, res)
}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Add --server host:port pointing at a peer with discovery service enabled (e.g. --peer0.org1.example.com:7051)
  2. Fix the shell variable so it expands to a non-empty address
  3. Set a default in the wrapper script and validate it is non-empty before invoking discover

Example fix

// before
discover --configFile conf.yaml peers   # no --server

// after
discover --configFile conf.yaml peers --server peer0.org1.example.com:7051
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.DISCOVERY_SERVER || process.env.DISCOVERY_SERVER.trim() === '') {
  throw new Error('Set DISCOVERY_SERVER (host:port of a peer) before running discover');
}

Type guard

function hasServer(pc) {
  return typeof pc.server === 'string' && pc.server.trim().length > 0;
}

Try / catch

try {
  execSync(`discover ... --server ${server} peers`);
} catch (e) {
  if (String(e).includes('no server specified')) {
    console.error('Pass --server peer0.org1.example.com:7051');
  }
}

Prevention

When it happens

Trigger: Running `discover peers` or `discover config` without --server, or with --server "" (e.g. an unset shell variable expanded to empty).

Common situations: Shell scripts where a $PEER_ADDR variable is unset; forgetting the flag in interactive use; automation templates missing the server argument for one subcommand.

Understand the failure class

Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/63865b1beec09fc9. Report an issue: GitHub.