apache/beam · error

expected 1 option, got

Error message

expected 1 option, got %v: %v

What it means

The GCS billing-project Init hook accepts at most one option (the requester-pays billing project). Passing more than one option to the hook registration triggers this error at init time, because there is exactly one billing project per filesystem configuration.

Solutions

  1. Pass exactly one billing project option (or none to skip billing-project config).
  2. Deduplicate/trim the options slice before registering the hook.
  3. Register RequesterBillingProject only once per pipeline.
  4. Check for repeated hook-enable calls in shared setup code.

Example fix

// before
hooks.EnableHook(projectBillingHook, "proj-a", "proj-b") // >1 option
// after
hooks.EnableHook(projectBillingHook, "proj-a") // exactly one option
Defensive patterns

Strategy: validation

Validate before calling

if len(opts) > 1 { return errors.New("projectBillingHook accepts at most 1 option") }

Try / catch

if err := hookInit(...); err != nil && strings.Contains(err.Error(), "expected 1 option") {
	log.Fatalf("billing project hook misconfigured: %v", err)
}

Prevention

When it happens

Trigger: Registering the projectBillingHook (via the hooks package / RequesterBillingProject plumbing) with two or more options in the opts slice; the hook's Init function then returns this error during startup.

Common situations: Accidentally accumulating options across multiple calls; passing a variadic slice with duplicates; wiring up the hook manually with a slice of several candidate projects.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/631b604454b26032. Report an issue: GitHub.

Appendix: source

Thrown at sdks/go/pkg/beam/io/filesystem/gcs/gcs.go:125

		}
	}

	result.WriteString("$") // match end
	return regexp.Compile(result.String())
}

var billingProject string = ""

func init() {
	filesystem.Register("gs", New)
	hf := func(opts []string) hooks.Hook {
		return hooks.Hook{
			Init: func(ctx context.Context) (context.Context, error) {
				if len(opts) == 0 {
					return ctx, nil
				}
				if len(opts) > 1 {
					return ctx, fmt.Errorf("expected 1 option, got %v: %v", len(opts), opts)
				}

				billingProject = opts[0]
				return ctx, nil
			},
		}
	}
	hooks.RegisterHook(projectBillingHook, hf)
}

type fs struct {
	client *storage.Client
}

// New creates a new Google Cloud Storage filesystem using application
// default credentials. If it fails, it falls back to unauthenticated
// access.
// It will use the environment variable named `BILLING_PROJECT_ID` as requester payer bucket attribute.

View on GitHub (pinned to 12126d8942)