dotnet/aspnetcore · error · Error

The ' ' argument should not be empty.

Error message

The '${name}' argument should not be empty.

What it means

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.

Solutions

  1. Trim and verify the URL is non-empty before calling withUrl: const url = (config.hubUrl ?? '').trim(); if (!url) fail fast.
  2. Audit the source of the string - env vars, config files, CLI args - for whitespace-only or empty values.
  3. Use a URL schema/validator (e.g. zod, yup) on the config object so empty strings surface at load time, not at HubConnection construction.

Example fix

// before
const url = process.env.HUB_URL; // '   ' in .env
const conn = new HubConnectionBuilder().withUrl(url).build(); // throws

// after
const url = (process.env.HUB_URL ?? '').trim();
if (!url) throw new Error('HUB_URL must be a non-empty URL');
const conn = new HubConnectionBuilder().withUrl(url).build();
Defensive patterns

Strategy: validation

Validate before calling

function assertNonEmptyString(value: unknown, name: string): asserts value is string {
  if (typeof value !== 'string' || /^\s*$/.test(value)) {
    throw new Error(`'${name}' must be a non-empty, non-whitespace string.`);
  }
}

const url = (process.env.HUB_URL ?? '').trim();
assertNonEmptyString(url, 'url');
const conn = new HubConnectionBuilder().withUrl(url).build();

Type guard

function isNonEmptyString(value: unknown): value is string {
  return typeof value === 'string' && !/^\s*$/.test(value);
}

Try / catch

try {
  builder.withUrl(url);
} catch (e) {
  if (e instanceof Error && /should not be empty/.test(e.message)) {
    // trim, fix the config source, then retry
  } else throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11). Data as JSON: /api/errors/a3c2b804e40bbd30. Report an issue: GitHub.

Appendix: source

Thrown at src/SignalR/clients/ts/signalr/src/Utils.ts:25

import { IStreamSubscriber, ISubscription } from "./Stream";
import { Subject } from "./Subject";
import { IHttpConnectionOptions } from "./IHttpConnectionOptions";
import { VERSION } from "./pkg-version";

// Version token that will be replaced by the prepack command
/** The version of the SignalR client. */

export { VERSION };
/** @private */
export class Arg {
    public static isRequired(val: any, name: string): void {
        if (val === null || val === undefined) {
            throw new Error(`The '${name}' argument is required.`);
        }
    }
    public static isNotEmpty(val: string, name: string): void {
        if (!val || val.match(/^\s*$/)) {
            throw new Error(`The '${name}' argument should not be empty.`);
        }
    }

    public static isIn(val: any, values: any, name: string): void {
        // TypeScript enums have keys for **both** the name and the value of each enum member on the type itself.
        if (!(val in values)) {
            throw new Error(`Unknown ${name} value: ${val}.`);
        }
    }
}

/** @private */
export class Platform {
    // react-native has a window but no document so we should check both
    public static get isBrowser(): boolean {
        return !Platform.isNode && typeof window === "object" && typeof window.document === "object";
    }

View on GitHub (pinned to 3600ca084e)