diff --git a/cmd/crowdsec/main.go b/cmd/crowdsec/main.go index 8d1bf903b31..2d61e61e1b2 100644 --- a/cmd/crowdsec/main.go +++ b/cmd/crowdsec/main.go @@ -98,7 +98,7 @@ func LoadBuckets(cConfig *csconfig.Config, hub *cwhub.Hub) error { holders, outputEventChan, err = leakybucket.LoadBuckets(cConfig.Crowdsec, hub, scenarios, &bucketsTomb, buckets, flags.OrderEvent) if err != nil { - return fmt.Errorf("scenario loading failed: %w", err) + return err } if cConfig.Prometheus != nil && cConfig.Prometheus.Enabled { diff --git a/pkg/leakybucket/manager_load.go b/pkg/leakybucket/manager_load.go index 15c6b97de71..89a49c4005d 100644 --- a/pkg/leakybucket/manager_load.go +++ b/pkg/leakybucket/manager_load.go @@ -301,8 +301,7 @@ func loadBucketFactoriesFromFile(item *cwhub.Item, hub *cwhub.Hub, buckets *Buck err = LoadBucket(&bucketFactory, tomb) if err != nil { - log.Errorf("Failed to load bucket %s: %v", bucketFactory.Name, err) - return nil, fmt.Errorf("loading of %s failed: %w", bucketFactory.Name, err) + return nil, fmt.Errorf("bucket %s: %w", bucketFactory.Name, err) } bucketFactory.orderEvent = orderEvent @@ -375,7 +374,7 @@ func LoadBucket(bucketFactory *BucketFactory, tomb *tomb.Tomb) error { if bucketFactory.Filter == "" { bucketFactory.logger.Warning("Bucket without filter, abort.") - return errors.New("bucket without filter directive") + return errors.New("missing filter directive") } bucketFactory.RunTimeFilter, err = expr.Compile(bucketFactory.Filter, exprhelpers.GetExprOptions(map[string]any{"evt": &pipeline.Event{}})...) diff --git a/test/bats/scenarios.bats b/test/bats/scenarios.bats new file mode 100644 index 00000000000..de18a225376 --- /dev/null +++ b/test/bats/scenarios.bats @@ -0,0 +1,34 @@ +#!/usr/bin/env bats + +set -u + +setup_file() { + load "../lib/setup_file.sh" +} + +teardown_file() { + load "../lib/teardown_file.sh" +} + +setup() { + load "../lib/setup.sh" + ./instance-data load +} + +teardown() { + ./instance-crowdsec stop +} + +#---------- + +@test "misconfigured scenario" { + CONFIG_DIR=$(dirname "$CONFIG_YAML") + mkdir -p "$CONFIG_DIR/scenarios/local" + echo "name: foo" >"$CONFIG_DIR/scenarios/local/foo.yaml" + config_set '.common.log_media="stdout"' + rune -1 "$CROWDSEC" + # XXX: + assert_stderr --partial "Bucket without filter, abort." + assert_stderr --partial "crowdsec init: while loading scenarios: bucket foo: missing filter directive" + refute_output +}