{"record":{"id":"f62ee83eaad630f3","repo":"denoland/deno","slug":"err-trace-events-category-required","errorCode":"ERR_TRACE_EVENTS_CATEGORY_REQUIRED","errorMessage":"At least one category is required","messagePattern":"At least one category is required","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/trace_events.ts","lineNumber":184,"sourceCode":"      }\n      enabledTracingObjects.delete(this);\n    }\n  }\n\n  get enabled() {\n    return this[kEnabled];\n  }\n\n  get categories() {\n    return ArrayPrototypeJoin(this[kCategories], \",\");\n  }\n}\n\nfunction createTracing(options) {\n  validateObject(options, \"options\");\n  validateStringArray(options.categories, \"options.categories\");\n  if (options.categories.length <= 0) {\n    throw new ERR_TRACE_EVENTS_CATEGORY_REQUIRED();\n  }\n  return new Tracing(options.categories);\n}\n\nfunction getEnabledCategories() {\n  const seen = new SafeSet();\n  for (const tracing of new SafeSetIterator(enabledTracingObjects)) {\n    for (const category of new SafeArrayIterator(tracing[kCategories])) {\n      seen.add(category);\n    }\n  }\n  if (seen.size === 0) {\n    return undefined;\n  }\n  return ArrayPrototypeJoin(ArrayFrom(seen), \",\");\n}\n\nfunction nowMicros() {","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/trace_events.ts#L166-L202","documentation":"`trace_events.createTracing(options)` enables a tracing session for a list of category strings. `options` must be an object, `options.categories` a string array, and — after those checks — a non-empty array, because a session with zero categories could never record events; empty arrays throw ERR_TRACE_EVENTS_CATEGORY_REQUIRED. Deno's polyfill mirrors Node's validation even where tracing itself is largely stubbed.","triggerScenarios":"`traceEvents.createTracing({ categories: [] })`; a list built as `'node,http'.split(',').filter(Boolean)` when the config string is empty; categories computed from flags that are all disabled in some environment.","commonSituations":"Diagnostics tooling ported from Node; environment-specific category config that resolves to zero entries in staging; feature-flagged tracing where every category is off.","solutions":["Skip createTracing entirely when the category list resolves to empty","Fall back to a default non-empty category list such as ['node']","Validate and warn on empty category config at startup"],"exampleFix":"// before\nconst categories = cfg.traceCategories.split(\",\").filter(Boolean);\nconst tracing = traceEvents.createTracing({ categories });\n\n// after\nconst categories = cfg.traceCategories.split(\",\").filter(Boolean);\nconst tracing = categories.length > 0\n  ? traceEvents.createTracing({ categories })\n  : null;","handlingStrategy":"validation","validationCode":"const categories = raw.filter((c): c is string => typeof c === \"string\" && c.length > 0);\nconst tracing = categories.length > 0\n  ? traceEvents.createTracing({ categories })\n  : null;","typeGuard":"const hasTracingCategories = (o: unknown): o is { categories: string[] } =>\n  typeof o === \"object\" && o !== null &&\n  Array.isArray((o as { categories?: unknown }).categories) &&\n  (o as { categories: unknown[] }).categories.length > 0;","tryCatchPattern":"try {\n  tracing = traceEvents.createTracing({ categories });\n} catch (e: any) {\n  if (e?.code === \"ERR_TRACE_EVENTS_CATEGORY_REQUIRED\") {\n    tracing = traceEvents.createTracing({ categories: [\"node\"] });\n  } else {\n    throw e;\n  }\n}","preventionTips":["Treat an empty category list as tracing-off and skip createTracing","Validate trace config at startup, not on the hot path","Keep a non-empty default category list"],"tags":["trace-events","diagnostics","node-compat","validation"],"backgroundTag":"missing-required-option","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T04:17:50.494Z"}