{"record":{"id":"a3c2b804e40bbd30","repo":"dotnet/aspnetcore","slug":"the-name-argument-should-not-be-empty","errorCode":null,"errorMessage":"The '${name}' argument should not be empty.","messagePattern":"The '(.+?)' argument should not be empty\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/ts/signalr/src/Utils.ts","lineNumber":25,"sourceCode":"import { 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 {\n    // react-native has a window but no document so we should check both\n    public static get isBrowser(): boolean {\n        return !Platform.isNode && typeof window === \"object\" && typeof window.document === \"object\";\n    }\n","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/SignalR/clients/ts/signalr/src/Utils.ts#L7-L43","documentation":"Thrown by Arg.isNotEmpty when a string argument is falsy or matches /^\\s*$/ (only whitespace). Stronger than isRequired - a non-null but blank string is rejected. Used primarily by HubConnectionBuilder.withUrl to catch empty/whitespace URLs after isRequired has already passed.","triggerScenarios":"withUrl(''), withUrl('   '), or withUrl passed a string that is entirely whitespace. The check runs only on string-typed arguments validated through isNotEmpty (url in HubConnectionBuilder is the main call site).","commonSituations":"URL loaded from config that resolved to an empty string; copy/paste left a placeholder blank; trailing whitespace from a YAML/env file; a templating step substituted an empty variable.","solutions":["Trim and verify the URL is non-empty before calling withUrl: const url = (config.hubUrl ?? '').trim(); if (!url) fail fast.","Audit the source of the string - env vars, config files, CLI args - for whitespace-only or empty values.","Use a URL schema/validator (e.g. zod, yup) on the config object so empty strings surface at load time, not at HubConnection construction."],"exampleFix":"// before\nconst url = process.env.HUB_URL; // '   ' in .env\nconst conn = new HubConnectionBuilder().withUrl(url).build(); // throws\n\n// after\nconst url = (process.env.HUB_URL ?? '').trim();\nif (!url) throw new Error('HUB_URL must be a non-empty URL');\nconst conn = new HubConnectionBuilder().withUrl(url).build();","handlingStrategy":"validation","validationCode":"function assertNonEmptyString(value: unknown, name: string): asserts value is string {\n  if (typeof value !== 'string' || /^\\s*$/.test(value)) {\n    throw new Error(`'${name}' must be a non-empty, non-whitespace string.`);\n  }\n}\n\nconst url = (process.env.HUB_URL ?? '').trim();\nassertNonEmptyString(url, 'url');\nconst conn = new HubConnectionBuilder().withUrl(url).build();","typeGuard":"function isNonEmptyString(value: unknown): value is string {\n  return typeof value === 'string' && !/^\\s*$/.test(value);\n}","tryCatchPattern":"try {\n  builder.withUrl(url);\n} catch (e) {\n  if (e instanceof Error && /should not be empty/.test(e.message)) {\n    // trim, fix the config source, then retry\n  } else throw e;\n}","preventionTips":["Trim user/config-supplied strings before passing them in.","Use a config schema validator (zod/yup) so empty strings surface at load time.","Treat empty/whitespace as a configuration error, not a runtime retry."],"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"}