{"record":{"id":"5d06e3e1210ea206","repo":"dotnet/aspnetcore","slug":"the-name-argument-is-required","errorCode":null,"errorMessage":"The '${name}' argument is required.","messagePattern":"The '(.+?)' argument is required\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/ts/signalr/src/Utils.ts","lineNumber":20,"sourceCode":"// The .NET Foundation licenses this file to you under the MIT license.\n\nimport { HttpClient } from \"./HttpClient\";\nimport { ILogger, LogLevel } from \"./ILogger\";\nimport { NullLogger } from \"./Loggers\";\nimport { IStreamSubscriber, ISubscription } from \"./Stream\";\nimport { Subject } from \"./Subject\";\nimport { IHttpConnectionOptions } from \"./IHttpConnectionOptions\";\nimport { VERSION } from \"./pkg-version\";\n\n// Version token that will be replaced by the prepack command\n/** The version of the SignalR client. */\n\nexport { VERSION };\n/** @private */\nexport class Arg {\n    public static isRequired(val: any, name: string): void {\n        if (val === null || val === undefined) {\n            throw new Error(`The '${name}' argument is required.`);\n        }\n    }\n    public static isNotEmpty(val: string, name: string): void {\n        if (!val || val.match(/^\\s*$/)) {\n            throw new Error(`The '${name}' argument should not be empty.`);\n        }\n    }\n\n    public static isIn(val: any, values: any, name: string): void {\n        // TypeScript enums have keys for **both** the name and the value of each enum member on the type itself.\n        if (!(val in values)) {\n            throw new Error(`Unknown ${name} value: ${val}.`);\n        }\n    }\n}\n\n/** @private */\nexport class Platform {","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/SignalR/clients/ts/signalr/src/Utils.ts#L2-L38","documentation":"Thrown by Arg.isRequired when a required argument is null or undefined. It is the standard precondition guard used across the TS client - HubConnectionBuilder.withUrl/withHubProtocol/withHubProtocol/configureLogging, HttpConnection, WebSocketTransport, LongPollingTransport, ServerSentEventsTransport all validate their inputs through it. The ${name} token is the human-readable argument name supplied at each call site.","triggerScenarios":"Calling HubConnectionBuilder.withUrl(null) or .withUrl(undefined); constructing HubConnection without a connection/logger/protocol; building a transport with an unset url or transferFormat; passing an undefined configurer to configureLogging.","commonSituations":"Reading the hub URL from an env var/config that is not set (returns undefined); calling builder methods in the wrong order so a later step overwrites a value with undefined; tree-shaking or partial imports leaving a dependency undefined; refactoring that renames a variable but leaves the old null-valued one in the builder chain.","solutions":["Check the stack trace - the ${name} in the message names the exact missing argument (e.g. 'url', 'connection', 'protocol', 'logger').","Ensure the value is set before passing it: load and validate configuration (env var / config file) before calling the builder.","Default the value where sensible, e.g. url = process.env.HUB_URL ?? throwOnMissing(), never pass undefined.","Confirm every required builder method is called: withUrl, withHubProtocol (or default JsonHubProtocol), configureLogging."],"exampleFix":"// before\nconst conn = new HubConnectionBuilder()\n  .withUrl(hubUrl) // hubUrl is undefined when env var missing\n  .build();\n\n// after\nif (!hubUrl) throw new Error('HUB_URL env var is required');\nconst conn = new HubConnectionBuilder().withUrl(hubUrl).build();","handlingStrategy":"validation","validationCode":"function assertRequired<T>(value: T | null | undefined, name: string): asserts value is T {\n  if (value === null || value === undefined) {\n    throw new Error(`Pre-check failed: '${name}' is required.`);\n  }\n}\n\nassertRequired(hubUrl, 'url');\nconst conn = new HubConnectionBuilder().withUrl(hubUrl).build();","typeGuard":"function isPresent<T>(value: T | null | undefined): value is T {\n  return value !== null && value !== undefined;\n}","tryCatchPattern":"try {\n  const conn = new HubConnectionBuilder()\n    .withUrl(url)\n    .withHubProtocol(protocol)\n    .configureLogging(logger)\n    .build();\n} catch (e) {\n  if (e instanceof Error && /argument is required/.test(e.message)) {\n    // the ${name} in the message tells you which one; fix the config source\n  } else throw e;\n}","preventionTips":["Validate configuration at load time (env/config schema) so undefined never reaches the builder.","Read the argument name in the error message - it identifies exactly which value is missing.","Build a small wrapper that fails fast with your own message before delegating to the SignalR builder."],"tags":["signalr","typescript","argument-validation","precondition"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}