Reject weight 0, a never-numeric calc operand and a repeat product past the cap; the CLI classifies ErrNoData
Tests / vet + fmt + tests (pull_request) Successful in 52s

This commit is contained in:
2026-09-02 18:23:03 +02:00
parent 34c933b2b3
commit 1b1b93b35f
8 changed files with 89 additions and 17 deletions
+5 -1
View File
@@ -16,6 +16,7 @@ import (
crand "crypto/rand"
"embed"
"encoding/binary"
"errors"
"fmt"
"io/fs"
"math/rand/v2"
@@ -27,6 +28,9 @@ import (
//go:embed data
var shippedFS embed.FS
// ErrNoData is returned by New when no source is loaded at all.
var ErrNoData = errors.New("no data: WithoutShippedData needs at least one WithDataPath or WithDataFS")
// Generator generates fake data from a loaded namespace tree. Create one with [New].
// It is safe for concurrent use; a seeded sequence is reproducible only when drawn
// from one goroutine.
@@ -99,7 +103,7 @@ func New(opts ...Option) (*Generator, error) {
}
sources = append(sources, c.sources...)
if len(sources) == 0 {
return nil, fmt.Errorf("fejkdata: no data: WithoutShippedData needs at least one WithDataPath or WithDataFS")
return nil, fmt.Errorf("fejkdata: %w", ErrNoData)
}
cats, err := loadData(sources)
if err != nil {