abhigyanpatwari/GitNexus · error · Error

embedding device must be one of auto, dml, cuda, cpu, wasm;

Error message

embedding device must be one of auto, dml, cuda, cpu, wasm; got "${value}"

What it means

Thrown by parseDevice() in config.ts when GITNEXUS_EMBEDDING_DEVICE is set to a value outside the closed set {auto, dml, cuda, cpu, wasm}. The device string is passed straight to transformers.js's pipeline() options.device, so an unrecognized value would either crash inside ONNX Runtime or silently be ignored. Validating up front gives an actionable error naming the allowed set instead of a downstream native crash.

Source

Thrown at gitnexus/src/core/embeddings/config.ts:71

  const parsed = Number(value);
  if (!Number.isInteger(parsed) || parsed <= 0) {
    throw new Error(`${name} must be a positive integer, got "${value}"`);
  }
  return parsed;
};

const parseDevice = (value: string | undefined): EmbeddingConfig['device'] | undefined => {
  if (value === undefined) return undefined;
  if (
    value === 'auto' ||
    value === 'dml' ||
    value === 'cuda' ||
    value === 'cpu' ||
    value === 'wasm'
  ) {
    return value;
  }
  throw new Error(`embedding device must be one of auto, dml, cuda, cpu, wasm; got "${value}"`);
};

export const resolveEmbeddingConfig = (
  overrides: Partial<EmbeddingConfig> = {},
): EmbeddingConfig => {
  const env = process.env;
  return {
    ...DEFAULT_EMBEDDING_CONFIG,
    ...overrides,
    batchSize: parsePositiveInt(
      'GITNEXUS_EMBEDDING_BATCH_SIZE',
      env.GITNEXUS_EMBEDDING_BATCH_SIZE,
      overrides.batchSize ?? DEFAULT_EMBEDDING_CONFIG.batchSize,
    ),
    subBatchSize: parsePositiveInt(
      'GITNEXUS_EMBEDDING_SUB_BATCH_SIZE',
      env.GITNEXUS_EMBEDDING_SUB_BATCH_SIZE,
      overrides.subBatchSize ?? DEFAULT_EMBEDDING_CONFIG.subBatchSize,

View on GitHub (pinned to d540b00184)

Solutions

  1. Set GITNEXUS_EMBEDDING_DEVICE to exactly one of auto, dml, cuda, cpu, or wasm (lowercase).
  2. Prefer 'auto' — it probes for CUDA/DirectML and falls back to cpu.
  3. Unset the variable to accept the default ('auto').

Example fix

// before
export GITNEXUS_EMBEDDING_DEVICE=gpu
// after
export GITNEXUS_EMBEDDING_DEVICE=auto
Defensive patterns

Strategy: validation

Validate before calling

const VALID_DEVICES = ['auto', 'dml', 'cuda', 'cpu', 'wasm'] as const;
const dev = process.env.GITNEXUS_EMBEDDING_DEVICE;
if (dev !== undefined && !VALID_DEVICES.includes(dev as any)) {
  throw new Error(`GITNEXUS_EMBEDDING_DEVICE=${dev} invalid; choose one of ${VALID_DEVICES.join(', ')}`);
}

Type guard

const isEmbeddingDevice = (v: string): v is 'auto' | 'dml' | 'cuda' | 'cpu' | 'wasm' =>
  ['auto', 'dml', 'cuda', 'cpu', 'wasm'].includes(v);

Prevention

When it happens

Trigger: resolveEmbeddingConfig() calls parseDevice(env.GITNEXUS_EMBEDDING_DEVICE) at config.ts:96-99. Fires on typos like gpu, metal, cudaa, auto-detect, or case variants like CUDA (the check is case-sensitive lowercase).

Common situations: Typing gpu or metal (common mental models from other ML stacks); using uppercase CUDA/CPU from a CI YAML that uppercases env vars; a copy-paste of 'auto ' with a trailing space; setting 'wasm' on a platform that actually can't use it (this error fires before that downstream check).

Related errors


AI-assisted analysis of abhigyanpatwari/GitNexus@d540b00184 (2026-08-12). Data as JSON: /api/errors/ac74a6c7cefe4fe7. Report an issue: GitHub.