juicedata/juicefs · warning

unsupported type: %T

Error message

unsupported type: %T

What it means

extractCustomConfig is generic over `string | int` and dispatches on the dynamic type of the default value. The default branch returns this error if the generic helper is ever instantiated with a default of any other type, indicating an internal programming error in the caller rather than a user-input problem.

Source

Thrown at pkg/meta/sql.go:311

func extractCustomConfig[T string | int](value *url.Values, key string, defaultV T) (T, error) {
	if value == nil {
		return defaultV, nil
	}
	if v := value.Get(key); v != "" {
		value.Del(key)
		var result T
		switch any(defaultV).(type) {
		case int:
			parsedInt, err := strconv.Atoi(v)
			if err != nil {
				return defaultV, fmt.Errorf("failed to parse value as int: %v", err)
			}
			result = any(parsedInt).(T)
		case string:
			result = any(v).(T)
		default:
			return defaultV, fmt.Errorf("unsupported type: %T", defaultV)
		}
		return result, nil
	} else {
		return defaultV, nil
	}
}

type prefixMapper struct {
	mapper names.Mapper
	prefix string
}

func (m prefixMapper) Obj2Table(name string) string {
	if name == "sliceRef" {
		return m.prefix + "chunk_ref"
	}
	return m.prefix + m.mapper.Obj2Table(name)
}

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Change the call site so the default value is a string or int (the only supported generic types).
  2. If a new type is genuinely needed, extend the switch in extractCustomConfig (e.g. `case bool:` with strconv.ParseBool).
  3. Add a test instantiating the helper only with string|int to catch regressions.

Example fix

// before
v, err := extractCustomConfig(values, "flag", false)
// after
v, err := extractCustomConfig(values, "flag", 0) // or extend the switch for bool
Defensive patterns

Strategy: type-guard

Validate before calling

// compile-time guard for supported default types
var _ = []interface{}{extractCustomConfig[int], extractCustomConfig[string]}

Type guard

func supportedDefault[T any](d T) bool {
    switch any(d).(type) {
    case int, string:
        return true
    }
    return false
}

Try / catch

if err != nil {
    if strings.Contains(err.Error(), "unsupported type") {
        // programmer error: fix the generic instantiation, not runtime config
    }
}

Prevention

When it happens

Trigger: A developer adds a call site of extractCustomConfig with a default value whose type is neither string nor int (e.g. `extractCustomConfig(values, "flag", false)`); the type switch falls through to default and returns this error at runtime.

Common situations: Refactors extending the helper to new settings types without extending the type switch; practically never hit by end users of a released JuiceFS build.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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