{"record":{"id":"f9f5f1d3ee4009d2","repo":"OrchardCMS/OrchardCore","slug":"the-hubconnection-url-must-be-a-valid-url","errorCode":null,"errorMessage":"The HubConnection url must be a valid url.","messagePattern":"The HubConnection url must be a valid url\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.SignalR/wwwroot/Scripts/signalr.js","lineNumber":1254,"sourceCode":"     */\n    get connectionId() {\n        return this.connection ? (this.connection.connectionId || null) : null;\n    }\n    /** Indicates the url of the {@link HubConnection} to the server. */\n    get baseUrl() {\n        return this.connection.baseUrl || \"\";\n    }\n    /**\n     * Sets a new url for the HubConnection. Note that the url can only be changed when the connection is in either the Disconnected or\n     * Reconnecting states.\n     * @param {string} url The url to connect to.\n     */\n    set baseUrl(url) {\n        if (this._connectionState !== HubConnectionState.Disconnected && this._connectionState !== HubConnectionState.Reconnecting) {\n            throw new Error(\"The HubConnection must be in the Disconnected or Reconnecting state to change the url.\");\n        }\n        if (!url) {\n            throw new Error(\"The HubConnection url must be a valid url.\");\n        }\n        this.connection.baseUrl = url;\n    }\n    /** Starts the connection.\n     *\n     * @returns {Promise<void>} A Promise that resolves when the connection has been successfully established, or rejects with an error.\n     */\n    start() {\n        this._startPromise = this._startWithStateTransitions();\n        return this._startPromise;\n    }\n    async _startWithStateTransitions() {\n        if (this._connectionState !== HubConnectionState.Disconnected) {\n            return Promise.reject(new Error(\"Cannot start a HubConnection that is not in the 'Disconnected' state.\"));\n        }\n        this._connectionState = HubConnectionState.Connecting;\n        this._logger.log(LogLevel.Debug, \"Starting HubConnection.\");\n        try {","sourceCodeStart":1236,"sourceCodeEnd":1272,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.SignalR/wwwroot/Scripts/signalr.js#L1236-L1272","documentation":"The baseUrl setter validates that the supplied url is truthy before applying it; an empty string, null, or undefined throws 'The HubConnection url must be a valid url.' This guards against silently configuring a connection with no endpoint, which would fail later at negotiate time with a much less obvious error.","triggerScenarios":"Setting hubConnection.baseUrl = '' , null, or undefined; building the URL from a config value or environment variable that is empty at runtime and passing it straight to the setter.","commonSituations":"Missing appsettings/environment config in deployment; concatenating a base path that resolves to empty string; reading a DOM attribute like data-hub-url that is absent, yielding ''. ","solutions":["Ensure the value passed to baseUrl is a non-empty, absolute URL before assignment.","Validate the configuration source (env var, app setting, DOM attribute) and fail fast with a clear message if it is missing.","Provide a sensible default URL (e.g. window.location.origin + '/hubs') when the configured value is empty.","Use withUrl(url) at construction time so a missing URL surfaces during initial configuration."],"exampleFix":"// before\nconnection.baseUrl = getConfig(\"hubUrl\"); // may be ''\n// after\nconst hubUrl = getConfig(\"hubUrl\");\nif (!hubUrl) {\n  throw new Error(\"hubUrl configuration value is missing\");\n}\nconnection.baseUrl = hubUrl;","handlingStrategy":"validation","validationCode":"function isValidHubUrl(url) {\n  if (!url || typeof url !== \"string\") return false;\n  try { new URL(url, window.location.origin); return true; } catch { return false; }\n}\nif (!isValidHubUrl(hubUrl)) throw new Error(\"hubUrl missing or invalid\");","typeGuard":"function isNonEmptyString(v) {\n  return typeof v === \"string\" && v.length > 0;\n}","tryCatchPattern":"try {\n  connection.baseUrl = hubUrl;\n} catch (err) {\n  if (err.message.includes(\"must be a valid url\")) {\n    console.error(\"Hub URL is empty — check configuration\");\n    hubUrl = defaultHubUrl;\n    connection.baseUrl = hubUrl;\n  } else { throw err; }\n}","preventionTips":["Validate hub URL config at application startup, before any connection attempt.","Add a startup assertion that all hub endpoint settings are non-empty.","Use typed config parsing that fails fast on missing values.","Never read hub URLs from optional DOM attributes without a fallback."],"tags":["signalr","validation","configuration"],"backgroundTag":"invalid-url-format","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}