Skip to content

Commit 4a9d86a

Browse files
committed
Fix lint warnings
1 parent 9d422b0 commit 4a9d86a

3 files changed

Lines changed: 32 additions & 21 deletions

File tree

web/src/observability/embeds.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const code = (s: string): string => `\`${s}\``;
5959
const link = (text: string, url: string): string => `[${text}](${url})`;
6060
const sub = (s: string): string => `-# ${s}`;
6161

62-
const truncate = (s: string, n: number): string => (s.length > n ? s.slice(0, n - 1) + "…" : s);
62+
const truncate = (s: string, n: number): string => (s.length > n ? `${s.slice(0, n - 1)}…` : s);
6363

6464
const ipLink = (ip: string): string => link(`\`${ip}\``, `https://ipinfo.io/${ip}`);
6565

@@ -74,7 +74,7 @@ const ispLink = (ctx: RequestContext): string => {
7474
return "unknown network";
7575
};
7676

77-
const ansi = (ansiCode: string, text: string): string => "```ansi\n\u001b[" + ansiCode + "m" + text + "\u001b[0m\n```";
77+
const ansi = (ansiCode: string, text: string): string => `\`\`\`ansi\n\u001b[${ansiCode}m${text}\u001b[0m\n\`\`\``;
7878

7979
const duration = (ms: number): string => {
8080
const totalSec = Math.floor(ms / 1000);
@@ -151,7 +151,7 @@ export function buildSessionStartedEmbed(e: SessionStartedEvent): DiscordEmbed {
151151
if (ctx.userAgent) {
152152
fields.push({
153153
name: "User-Agent",
154-
value: "```\n" + truncate(ctx.userAgent, LIMIT_UA_INLINE) + "\n```",
154+
value: `\`\`\`\n${truncate(ctx.userAgent, LIMIT_UA_INLINE)}\n\`\`\``,
155155
inline: false,
156156
});
157157
}
@@ -217,7 +217,7 @@ export function buildErrorEmbed(e: ErrorEvent): DiscordEmbed {
217217
lines.push(`### ✖ ${truncate(e.where, 120)}`, ansi("2;31", msg));
218218

219219
if (stack) {
220-
lines.push("```ts\n" + truncate(stack, LIMIT_STACK) + "\n```");
220+
lines.push(`\`\`\`ts\n${truncate(stack, LIMIT_STACK)}\n\`\`\``);
221221
}
222222

223223
const ctxSub = contextSubtext(e.context);
@@ -245,7 +245,7 @@ export function buildQueueEnteredEmbed(e: QueueEnteredEvent): DiscordEmbed {
245245

246246
const lines: string[] = [
247247
`### ${locationHeader(ctx)}`,
248-
sub(`position ${code("#" + e.position)} · ${capacityLine(e.capacity, { skipQueue: true })}`),
248+
sub(`position ${code(`#${e.position}`)} · ${capacityLine(e.capacity, { skipQueue: true })}`),
249249
];
250250

251251
const fields: DiscordEmbedField[] = [

web/src/queue/manager.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { type CapacitySnapshot, notify, OBS_CONTEXT_HEADER, parseContext } from
77
import { hashIP } from "../utils";
88
import {
99
QUEUE_PREFIX,
10-
RESOLVED_PREFIX,
11-
SESSION_PREFIX,
1210
queueKey,
11+
RESOLVED_PREFIX,
1312
resolvedKey,
13+
SESSION_PREFIX,
1414
sessionKey,
1515
stripResolvedPrefix,
1616
stripSessionPrefix,
@@ -181,7 +181,8 @@ export class SessionManager extends DurableObject<Env> {
181181
this.notifyAsync(
182182
notify.warning(this.env, {
183183
title: "Missing CF-Connecting-IP",
184-
description: "A request reached SessionManager without a CF-Connecting-IP header — per-IP rate limiting is disabled for this session",
184+
description:
185+
"A request reached SessionManager without a CF-Connecting-IP header — per-IP rate limiting is disabled for this session",
185186
context: parseContext(request.headers.get(OBS_CONTEXT_HEADER)),
186187
}),
187188
);
@@ -232,11 +233,11 @@ export class SessionManager extends DurableObject<Env> {
232233
const ticketId = url.searchParams.get("ticketId");
233234
if (!ticketId) return new Response("Missing ticketId", { status: 400 });
234235

235-
if (this.resolvedTickets.has(ticketId)) {
236-
const { sessionId, sessionType } = this.resolvedTickets.get(ticketId)!;
236+
const resolved = this.resolvedTickets.get(ticketId);
237+
if (resolved) {
237238
this.resolvedTickets.delete(ticketId);
238239
void this.ctx.storage.delete(resolvedKey(ticketId));
239-
return Response.json({ status: "READY", sessionId, sessionType });
240+
return Response.json({ status: "READY", sessionId: resolved.sessionId, sessionType: resolved.sessionType });
240241
}
241242

242243
const entry = this.waitingQueue.find((p) => p.ticketId === ticketId);

web/src/session/base.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ export class BaseSession extends Container<Env> {
264264
this.startRetries++;
265265
console.warn(`[onStop] Container died during provisioning, retry ${this.startRetries}/3`);
266266
await new Promise((r) => setTimeout(r, 2000));
267-
void this.startContainer(this.ctx.id.name!);
267+
void this.startContainer(this.sessionId);
268268
return;
269269
}
270270
await this.closeSession("container_stopped");
@@ -280,7 +280,8 @@ export class BaseSession extends Container<Env> {
280280
this.broadcast({
281281
type: "SYSTEM_NOTICE",
282282
payload: {
283-
message: "We just pushed an update to glua.dev. We can't hot-swap running sessions (yet), so yours had to be closed — sorry about that 🥀 Start a new one to pick up where you left off!",
283+
message:
284+
"We just pushed an update to glua.dev. We can't hot-swap running sessions (yet), so yours had to be closed — sorry about that 🥀 Start a new one to pick up where you left off!",
284285
},
285286
});
286287
await this.closeSession("deploy_rollout");
@@ -387,9 +388,12 @@ export class BaseSession extends Container<Env> {
387388
// ── Session timer ──
388389

389390
private timerPayload() {
391+
if (this.sessionEndTime === undefined || this.sessionDuration === undefined) {
392+
throw new Error("timerPayload called before session became active");
393+
}
390394
return {
391-
endTime: this.sessionEndTime!,
392-
duration: this.sessionDuration!,
395+
endTime: this.sessionEndTime,
396+
duration: this.sessionDuration,
393397
extensionThreshold: SESSION_TIMING.extensionThreshold,
394398
};
395399
}
@@ -480,7 +484,7 @@ export class BaseSession extends Container<Env> {
480484
await manager.fetch("http://do/api/session-closed", {
481485
method: "POST",
482486
headers: { "Content-Type": "application/json" },
483-
body: JSON.stringify({ sessionId: this.ctx.id.name! }),
487+
body: JSON.stringify({ sessionId: this.sessionId }),
484488
});
485489
}
486490

@@ -514,16 +518,16 @@ export class BaseSession extends Container<Env> {
514518

515519
private async flushLogsToR2() {
516520
if (this.logBuffer.length === 0) return;
517-
const logKey = `sessions/${this.ctx.id.name!}/logs.log`;
518-
const logsToFlush = this.logBuffer.join("\n") + "\n";
521+
const logKey = `sessions/${this.sessionId}/logs.log`;
522+
const logsToFlush = `${this.logBuffer.join("\n")}\n`;
519523
this.logBuffer = [];
520524

521525
try {
522526
const existingLog = await this.env.LOG_BUCKET.get(logKey);
523527
const existingContent = existingLog ? await existingLog.text() : "";
524528
await this.env.LOG_BUCKET.put(logKey, existingContent + logsToFlush);
525529
} catch (e) {
526-
console.error(`Failed to flush logs for ${this.ctx.id.name!}:`, e);
530+
console.error(`Failed to flush logs for ${this.sessionId}:`, e);
527531
this.logBuffer.unshift(...logsToFlush.trim().split("\n"));
528532
this.notifyAsync(
529533
notify.error(this.env, {
@@ -541,7 +545,7 @@ export class BaseSession extends Container<Env> {
541545
const hasNewScripts = Object.keys(this.scriptBuffer).length > 0;
542546
if (!hasNewScripts && !this.sessionMetadata) return;
543547

544-
const sessionKey = `sessions/${this.ctx.id.name!}/session.json`;
548+
const sessionKey = `sessions/${this.sessionId}/session.json`;
545549

546550
try {
547551
const existing = await this.env.LOG_BUCKET.get(sessionKey);
@@ -559,7 +563,7 @@ export class BaseSession extends Container<Env> {
559563
await this.env.LOG_BUCKET.put(sessionKey, JSON.stringify(session));
560564
this.scriptBuffer = {};
561565
} catch (e) {
562-
console.error(`Failed to flush session data for ${this.ctx.id.name!}:`, e);
566+
console.error(`Failed to flush session data for ${this.sessionId}:`, e);
563567
this.notifyAsync(
564568
notify.error(this.env, {
565569
where: "flushSessionToR2",
@@ -590,6 +594,12 @@ export class BaseSession extends Container<Env> {
590594
this.ctx.waitUntil(promise);
591595
}
592596

597+
private get sessionId(): string {
598+
const name = this.ctx.id.name;
599+
if (!name) throw new Error("Session DO constructed without idFromName");
600+
return name;
601+
}
602+
593603
private send(ws: WebSocket, message: ServerMessage): void {
594604
try {
595605
ws.send(JSON.stringify(message));

0 commit comments

Comments
 (0)