apache/beam · error

base64 decoding failed

Error message

base64 decoding failed

What it means

DecodeBase64 decodes a base64 string and unmarshals the result into a proto message. This error wraps a failure of base64.StdEncoding.DecodeString, meaning the input string is not valid standard-alphabet base64.

Solutions

  1. Ensure the input uses standard base64 alphabet with correct padding (strings.TrimSpace first, strip newlines)
  2. If the source emits URL-safe base64, convert it: replace '-' with '+' and '_' with '/' before decoding
  3. Regenerate the encoded value with EncodeBase64 rather than hand-editing

Example fix

// before
err := protox.DecodeBase64(urlSafeB64, msg)
// after
fixed := strings.NewReplacer("-", "+", "_", "/").Replace(strings.TrimSpace(urlSafeB64))
err := protox.DecodeBase64(fixed, msg)
Defensive patterns

Strategy: validation

Validate before calling

if _, err := base64.StdEncoding.DecodeString(strings.TrimSpace(s)); err != nil { return fmt.Errorf("not valid std base64: %w", err) }

Try / catch

if err := protox.DecodeBase64(s, msg); err != nil {
    var corr base64.CorruptInputError
    if errors.As(err, &corr) { /* normalize alphabet/padding and retry once */ }
    return err
}

Prevention

When it happens

Trigger: Calling DecodeBase64 (directly or via DecodeCoderRef, DecodeType, DecodeFn, makeCoder, makeLink, decodeDataflowCustomCoder) with a string containing invalid characters, wrong padding, or URL-safe base64 (- and _ instead of + and /).

Common situations: Pasting a URL-safe base64 blob (from a JSON web token or URL parameter) into a config expecting StdEncoding, copy/paste losing padding or adding whitespace/newlines, or manually editing a serialized coder reference.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at sdks/go/pkg/beam/core/util/protox/base64.go:47

		panic(err)
	}
	return ret
}

// EncodeBase64 encodes a proto wrapped in base64.
func EncodeBase64(msg proto.Message) (string, error) {
	data, err := proto.Marshal(msg)
	if err != nil {
		return "", err
	}
	return base64.StdEncoding.EncodeToString(data), nil
}

// DecodeBase64 decodes a base64 wrapped proto.
func DecodeBase64(data string, ret proto.Message) error {
	decoded, err := base64.StdEncoding.DecodeString(data)
	if err != nil {
		return errors.Wrap(err, "base64 decoding failed")
	}
	return proto.Unmarshal(decoded, ret)
}

View on GitHub (pinned to 12126d8942)