crowdsecurity/crowdsec · error

loading scenario dump file '%s': %w

Error message

loading scenario dump file '%s': %w

What it means

ScenarioAssert.LoadTest loads the serialized bucket dump (the .dump file produced when running the scenario) via LoadScenarioDump. If reading or unmarshalling that dump fails, the error is wrapped naming the dump file. It indicates the test's assertion input file is missing, unreadable, or in an unexpected format.

Source

Thrown at pkg/hubtest/scenario_assert.go:63

	return ScenarioAssert
}

func (s *ScenarioAssert) AutoGenFromFile(filename string) (string, error) {
	err := s.LoadTest(filename, "")
	if err != nil {
		return "", err
	}

	ret := s.AutoGenScenarioAssert()

	return ret, nil
}

func (s *ScenarioAssert) LoadTest(filename string, bucketpour string) error {
	bucketDump, err := LoadScenarioDump(filename)
	if err != nil {
		return fmt.Errorf("loading scenario dump file '%s': %w", filename, err)
	}

	s.TestData = bucketDump

	if bucketpour != "" {
		pourDump, err := dumps.LoadBucketPourDump(bucketpour)
		if err != nil {
			return fmt.Errorf("loading bucket pour dump file '%s': %w", filename, err)
		}

		s.PourData = pourDump
	}

	return nil
}

func (s *ScenarioAssert) AssertFile(testFile string) error {
	file, err := os.Open(s.File)

View on GitHub (pinned to 909b515798)

Solutions

  1. Re-run the test to (re)generate the dump file: cscli hubtest run <test>.
  2. Verify the dump file path exists and is readable.
  3. Regenerate dumps if they were produced by an older crowdsec version.
  4. Inspect the wrapped error to distinguish file-not-found from unmarshal failure.

Example fix

// before
assert.LoadTest("tests/ssh-bf/dump-but-no-dump-file", "")
// after
// run: cscli hubtest run ssh-bf  (creates the dump), then:
assert.LoadTest("tests/ssh-bf/dump", "")
Defensive patterns

Strategy: validation

Validate before calling

if fi, err := os.Stat(dumpFile); err != nil || fi.Size() == 0 {
	return fmt.Errorf("dump file %s missing or empty; run the test first", dumpFile)
}

Try / catch

if err := assert.LoadTest(dumpFile, pourFile); err != nil {
	if os.IsNotExist(errors.Unwrap(err)) {
		return fmt.Errorf("run 'cscli hubtest run' to generate %s first", dumpFile)
	}
	return err
}

Prevention

When it happens

Trigger: LoadTest (called by AutoGenFromFile or AssertFile) with a filename that doesn't exist, isn't readable, or contains an invalid/outdated dump serialization.

Common situations: Running assertions before generating the dump (cscli hubtest run not executed); dump file deleted by CI cleanup; dump produced by an older crowdsec version with a different serialization shape.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/8e019e9ad5809cf7. Report an issue: GitHub.