Skip to content

NATS CLI stream restore --config override silently ignored #1617

@jarretlavallee

Description

@jarretlavallee

Observed behavior

nats stream restore --config=<file> silently ignores the config file. The restored stream always uses the config from the backup, regardless of what --config points to.

Expected behavior

nats stream restore --config=<file> should use the specified config file.

Server and client version

Main on client

Host environment

No response

Steps to reproduce

Claude's analysis

Variable shadowing bug in cli/stream_command.go:1274 in nats-io/natscli.

// Line 1235: outer variable
var cfg *api.StreamConfig

// ...

// Line 1273-1287:
if c.inputFile != "" {
    cfg, err := c.loadConfigFile(c.inputFile)  // BUG: := shadows outer cfg
    if err != nil {
        return err
    }

    if bm.Config.Name != cfg.Name {
        return fmt.Errorf("stream names may not be changed during restore")
    }
} else {
    cfg = &bm.Config
}

// Line 1300-1302: outer cfg is still nil when --config is used
if cfg != nil {
    ropts = append(ropts, jsm.RestoreConfiguration(*cfg))
}

:= on line 1274 creates a new block-scoped cfg, shadowing the outer cfg from line 1235. Once the if block exits, the loaded config is gone. The outer cfg stays nil, RestoreConfiguration never gets added to the options, and the backup's embedded config (with the mirror) is used as-is.

Metadata

Metadata

Assignees

Labels

defectSuspected defect such as a bug or regression

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions