juicedata/juicefs · error

marshal worker config: %s

Error message

marshal worker config: %s

What it means

After locating source/destination, prepareWorkerCommand serializes the clusterWorkerConfig (source/destination URLs and env) to JSON to pipe to the worker over stdin. This error wraps any json.Marshal failure. In practice it is nearly impossible for this struct (three string/map fields), so it indicates an unexpected internal serialization problem.

Source

Thrown at pkg/sync/cluster.go:398

			workerArgs[i] = utils.RemovePassword(config.clusterSource)
			foundSource = true
		}
		if arg == config.clusterDestination {
			workerArgs[i] = utils.RemovePassword(config.clusterDestination)
			foundDestination = true
		}
	}
	if !foundSource || !foundDestination {
		return nil, nil, fmt.Errorf("can't locate source or destination in command arguments")
	}

	payload, err := json.Marshal(clusterWorkerConfig{
		Source:      config.clusterSource,
		Destination: config.clusterDestination,
		Env:         config.Env,
	})
	if err != nil {
		return nil, nil, fmt.Errorf("marshal worker config: %s", err)
	}

	args := []string{host, path}
	args = append(args, workerArgs...)
	args = append(args, "--manager", address)
	if !config.Verbose && !config.Quiet {
		args = append(args, "-q")
	}
	return shellescape.EscapeArgs(args), payload, nil
}

// ReadClusterWorkerConfig reads storage URLs and environment variables from worker stdin.
func ReadClusterWorkerConfig(r io.Reader) (string, string, map[string]string, error) {
	data, err := io.ReadAll(io.LimitReader(r, maxClusterWorkerConfigSize+1))
	if err != nil {
		return "", "", nil, fmt.Errorf("read worker config: %s", err)
	}
	if len(data) > maxClusterWorkerConfigSize {

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Inspect the wrapped error (%s) to identify the unmarshalable value
  2. Check for local modifications adding fields of unsupported types (chan, func, complex) to clusterWorkerConfig and change them to serializable types
  3. Ensure Env map values are plain strings, not custom types

Example fix

// before
Env: map[string]CustomType{...} // unmarshalable
// after
Env: map[string]string{"KEY": "value"}
Defensive patterns

Strategy: try-catch

Try / catch

payload, err := json.Marshal(cfg)
if err != nil {
	return fmt.Errorf("marshal worker config: %s", err)
}

Prevention

When it happens

Trigger: json.Marshal of the clusterWorkerConfig{Source, Destination, Env} struct returns an error — practically only if custom marshaling is added to the struct or Env contains a type that cannot be marshaled after a code change.

Common situations: Custom builds or patches that add unsupported field types (e.g. channels, funcs, NaN floats) to clusterWorkerConfig or Env; standard releases essentially never emit this.

Understand the failure class

Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.

Related errors


AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06). Data as JSON: /api/errors/b352b91af52090b4. Report an issue: GitHub.