{"record":{"id":"97c97e49e8203f9c","repo":"apache/beam","slug":"unable-to-deduce-name-please-use-withname","errorCode":null,"errorMessage":"Unable to deduce name, please use withName(...).","messagePattern":"Unable to deduce name, please use withName\\(\\.\\.\\.\\)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"sdks/typescript/src/apache_beam/transforms/transform.ts","lineNumber":66,"sourceCode":"  if (untyped.beamName !== null && untyped.beamName !== undefined) {\n    if (typeof untyped.beamName === \"string\") {\n      return untyped.beamName;\n    } else {\n      return untyped.beamName();\n    }\n  } else if (untyped.name && untyped.name !== \"anonymous\") {\n    return untyped.name;\n  } else {\n    const stringified = (\"\" + withName)\n      // Remove injected code coverage boilerplate.\n      .replace(/__cov_.*?[+][+]/g, \" \")\n      // Normalize whitespace.\n      .replace(/\\s+/gm, \" \")\n      .trim();\n    if (stringified.length < 60) {\n      return stringified;\n    } else {\n      throw new Error(\"Unable to deduce name, please use withName(...).\");\n    }\n  }\n}\n\n// NOTE: It could be more idiomatic javascript to simply use the function type\n// (InputT, Pipeline, runnerApi.PTransform) => OutputT rather than a transform\n// class hierarchy here, a class is chosen to serve as a more obvious\n// representative for other languages to follow.\n// This more functional form is still preferred for users, and accepted\n// as an argument to apply for the various pvalues (see pvalue.ts).\n//\n// Note also that the requirement for both a synchronous and asynchronous\n// variant is imposed by javascript, and is not necessarily relevant in other\n// languages (especially if an asynchronous call can be turned into a blocking\n// call rather than forcing the asynchronous nature all the way up the call\n// hierarchy).\n\n/** @internal */","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/typescript/src/apache_beam/transforms/transform.ts#L48-L84","documentation":"When a PTransform is created without an explicit name, extractName derives one by stringifying the transform's function/DoFn source code and normalizing whitespace. If the stringified source is 60 characters or longer, the name would be unwieldy, so the SDK throws and asks the developer to name the transform explicitly. This is a build-time convenience guard, not a runtime data error.","triggerScenarios":"Using map/flatMap/filter/combining with an anonymous multi-line or long function without calling .withName(...) or passing a name.","commonSituations":"Inline arrow functions with long bodies used directly in map/flatMap; minified/bundled code where function.toString() yields long text; developers unaware names are auto-derived.","solutions":["Call .withName(\"MyStepName\") on the transform.","Pass a short, named function instead of a long anonymous one.","Extract the logic into a named DoFn class so the class name is used.","Shorten the inline function so its source is under 60 characters."],"exampleFix":"// before\npcoll.map((x) => { const a = doLongThing(x); return alsoDo(a, more(x)); });\n\n// after\npcoll.map(enrich).withName(\"EnrichRecords\");","handlingStrategy":"try-catch","validationCode":"function hasShortSource(fn: Function) { return fn.toString().replace(/\\s+/gm, ' ').trim().length < 60; }","typeGuard":null,"tryCatchPattern":"try {\n  pcoll.map(longInlineFn);\n} catch (e) {\n  if (/Unable to deduce name/.test(String(e))) pcoll.map(longInlineFn).withName('Enrich');\n  else throw e;\n}","preventionTips":["Always call withName() on non-trivial transforms.","Keep inline lambdas short; extract logic into named functions/DoFns.","Beware minified bundles inflating function source length."],"tags":["naming","pipeline-graph","developer-experience"],"backgroundTag":"missing-required-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}