From 7e424a28bba0f7cb0d441e8bdad4dd6fb148cd23 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 6 Jan 2026 15:18:01 +0000 Subject: [PATCH] refactor: address code review feedback - improve error handling and remove unsafe assertions Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com> --- frontends/nextjs/src/lib/github/create-github-client.ts | 8 +++++++- .../nextjs/src/lib/github/fetch-workflow-run-logs.ts | 7 +++++-- .../src/lib/packages/json/render-json-component.tsx | 2 +- frontends/nextjs/src/lib/schema/schema-registry.ts | 4 ++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/frontends/nextjs/src/lib/github/create-github-client.ts b/frontends/nextjs/src/lib/github/create-github-client.ts index 1b883cced..1260a6b73 100644 --- a/frontends/nextjs/src/lib/github/create-github-client.ts +++ b/frontends/nextjs/src/lib/github/create-github-client.ts @@ -7,7 +7,13 @@ import { Octokit } from 'octokit' export type GitHubClient = Octokit export function createGitHubClient(token?: string): GitHubClient { + const authToken = token || process.env.GITHUB_TOKEN + + if (!authToken) { + throw new Error('GitHub token is required. Provide a token parameter or set GITHUB_TOKEN environment variable.') + } + return new Octokit({ - auth: token || process.env.GITHUB_TOKEN, + auth: authToken, }) } diff --git a/frontends/nextjs/src/lib/github/fetch-workflow-run-logs.ts b/frontends/nextjs/src/lib/github/fetch-workflow-run-logs.ts index 2fb613362..5c1261638 100644 --- a/frontends/nextjs/src/lib/github/fetch-workflow-run-logs.ts +++ b/frontends/nextjs/src/lib/github/fetch-workflow-run-logs.ts @@ -49,10 +49,13 @@ export async function fetchWorkflowRunLogs( // Parse arguments let opts: FetchWorkflowRunLogsOptions if (typeof ownerOrOptions === 'string') { + if (!repo || !runId) { + throw new Error('repo and runId are required when using positional arguments') + } opts = { owner: ownerOrOptions, - repo: repo!, - runId: runId!, + repo, + runId, tailLines: options?.tailLines, failedOnly: options?.failedOnly, } diff --git a/frontends/nextjs/src/lib/packages/json/render-json-component.tsx b/frontends/nextjs/src/lib/packages/json/render-json-component.tsx index ba1e98c67..ed0951aa4 100644 --- a/frontends/nextjs/src/lib/packages/json/render-json-component.tsx +++ b/frontends/nextjs/src/lib/packages/json/render-json-component.tsx @@ -277,7 +277,7 @@ function evaluateSimpleExpression(expr: string, context: RenderContext): JsonVal if (value && typeof value === 'object' && !Array.isArray(value)) { value = (value as Record)[part] } else { - return value + return undefined } } diff --git a/frontends/nextjs/src/lib/schema/schema-registry.ts b/frontends/nextjs/src/lib/schema/schema-registry.ts index f348de146..e83252036 100644 --- a/frontends/nextjs/src/lib/schema/schema-registry.ts +++ b/frontends/nextjs/src/lib/schema/schema-registry.ts @@ -44,7 +44,7 @@ export function loadSchemaRegistry(path?: string): SchemaRegistry { schemaRegistry.packages = packages } } catch (error) { - console.warn('Failed to load schema registry:', error) + console.warn(`Failed to load schema registry from ${schemaPath}:`, error instanceof Error ? error.message : String(error)) } return schemaRegistry @@ -60,7 +60,7 @@ export function saveSchemaRegistry(registry: SchemaRegistry, path?: string): voi } writeFileSync(schemaPath, JSON.stringify(data, null, 2)) } catch (error) { - console.error('Failed to save schema registry:', error) + console.error(`Failed to save schema registry to ${schemaPath}:`, error instanceof Error ? error.message : String(error)) } }