{"record":{"id":"2f13da29b806a448","repo":"laravel/framework","slug":"ably-error-s","errorCode":null,"errorMessage":"Ably error: %s","messagePattern":"Ably error: (.+?)","errorType":"exception","errorClass":"BroadcastException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Broadcasting/Broadcasters/AblyBroadcaster.php","lineNumber":134,"sourceCode":"     * Broadcast the given event.\n     *\n     * @param  array  $channels\n     * @param  string  $event\n     * @param  array  $payload\n     * @return void\n     *\n     * @throws \\Illuminate\\Broadcasting\\BroadcastException\n     */\n    public function broadcast(array $channels, $event, array $payload = [])\n    {\n        try {\n            foreach ($this->formatChannels($channels) as $channel) {\n                $this->ably->channels->get($channel)->publish(\n                    $this->buildAblyMessage($event, $payload)\n                );\n            }\n        } catch (AblyException $e) {\n            throw new BroadcastException(\n                sprintf('Ably error: %s', $e->getMessage())\n            );\n        }\n    }\n\n    /**\n     * Build an Ably message object for broadcasting.\n     *\n     * @param  string  $event\n     * @param  array  $payload\n     * @return \\Ably\\Models\\Message\n     */\n    protected function buildAblyMessage($event, array $payload = [])\n    {\n        return tap(new AblyMessage, function ($message) use ($event, $payload) {\n            $message->name = $event;\n            $message->data = $payload;\n            $message->connectionKey = data_get($payload, 'socket');","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Broadcasting/Broadcasters/AblyBroadcaster.php#L116-L152","documentation":"Thrown by AblyBroadcaster::broadcast() as a BroadcastException when the Ably SDK's channel publish() call raises an AblyException. The message embeds Ably's own error text (sprintf'd) so callers can see the upstream cause. It indicates the message was not delivered to Ably.","triggerScenarios":"Broadcasting an event on Ably where publish() fails — invalid/expired Ably key, insufficient channel capabilities, rate limit, network error, malformed channel name, or capacity/protocol errors returned by the Ably REST API.","commonSituations":"Wrong/rotated ABLY_KEY in .env; channel name with characters Ably rejects; capability rules that forbid publish on the channel; rate limiting under load; egress blocked from the host; Ably service incident.","solutions":["Verify ABLY_KEY is a valid, non-expired key with publish capability on the channels you use.","Check the embedded Ably error message for the specific code (e.g. 40102 invalid key, 40160 capability, 429 rate limit) and act on it.","Sanitize channel names per Ably rules (alphanumeric, :, -, _; max length).","For rate limits, batch events or reduce publish frequency.","Confirm network egress to rest.ably.io / the configured Ably host.","Wrap broadcast() in a try/catch for BroadcastException to queue a retry or report."],"exampleFix":"// before — broadcast swallows underlying Ably error\nbroadcast(new OrderShipped($order));\n\n// after — handle BroadcastException and surface Ably's message\ntry {\n    broadcast(new OrderShipped($order));\n} catch (\\Illuminate\\Broadcasting\\BroadcastException $e) {\n    Log::error('Ably broadcast failed', ['reason' => $e->getMessage()]);\n    // optionally retry or push to a queue for later delivery\n}\n// and fix credentials in .env:\n// ABLY_KEY=xxxxx.yyyyy:zzzzz","handlingStrategy":"try-catch","validationCode":"// PHP — pre-flight Ably key presence before broadcasting\nif (config('broadcasting.connections.ably.driver') === 'ably' && empty(config('broadcasting.connections.ably.key'))) {\n    throw new \\RuntimeException('ABLY_KEY is not set; Ably broadcast will fail.');\n}\nbroadcast(new \\App\\Events\\OrderShipped($order));","typeGuard":"// Heuristic guard for Ably readiness\nfunction ablyCredentialsAreConfigured(): bool {\n    $cfg = config('broadcasting.connections.ably');\n    return $cfg && ($cfg['driver'] ?? null) === 'ably' && ! empty($cfg['key']);\n}","tryCatchPattern":"try {\n    broadcast(new \\App\\Events\\OrderShipped($order));\n} catch (\\Illuminate\\Broadcasting\\BroadcastException $e) {\n    Log::error('Ably broadcast failed', ['reason' => $e->getMessage()]);\n    // queue for retry or push to a dead-letter\n    \\App\\Jobs\\RetryBroadcast::dispatch($event)->delay(now()->addSeconds(30));\n}","preventionTips":["Keep a valid ABLY_KEY with publish capability.","Sanitize channel names per Ably rules.","Catch BroadcastException and retry/queue instead of surfacing to the user.","Monitor the embedded Ably error codes (40102, 40160, 429) to act on root cause."],"tags":["broadcasting","ably","runtime","network","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}