From f38efdea4c5ffe13e9424b0aa2833bee28f1e34c Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Oct 2025 23:50:32 -0400 Subject: [PATCH] fix: gracefully fallback to body when body_path cannot be read (#671) * Initial plan * fix: gracefully fallback to body when body_path cannot be read Co-authored-by: chenrui333 <1580956+chenrui333@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: chenrui333 <1580956+chenrui333@users.noreply.github.com> --- __tests__/util.test.ts | 46 ++++++++++++++++++++++++++++++++++++++++++ src/util.ts | 15 ++++++++++---- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/__tests__/util.test.ts b/__tests__/util.test.ts index ab4fdd2..78c2b87 100644 --- a/__tests__/util.test.ts +++ b/__tests__/util.test.ts @@ -122,6 +122,52 @@ describe('util', () => { }), ); }); + it('falls back to body when body_path is missing', () => { + assert.equal( + releaseBody({ + github_ref: '', + github_repository: '', + github_token: '', + input_body: 'fallback-body', + input_body_path: '__tests__/does-not-exist.txt', + input_draft: false, + input_prerelease: false, + input_files: [], + input_overwrite_files: undefined, + input_preserve_order: undefined, + input_name: undefined, + input_tag_name: undefined, + input_target_commitish: undefined, + input_discussion_category_name: undefined, + input_generate_release_notes: false, + input_make_latest: undefined, + }), + 'fallback-body', + ); + }); + it('returns undefined when body_path is missing and body is not provided', () => { + assert.equal( + releaseBody({ + github_ref: '', + github_repository: '', + github_token: '', + input_body: undefined, + input_body_path: '__tests__/does-not-exist.txt', + input_draft: false, + input_prerelease: false, + input_files: [], + input_overwrite_files: undefined, + input_preserve_order: undefined, + input_name: undefined, + input_tag_name: undefined, + input_target_commitish: undefined, + input_discussion_category_name: undefined, + input_generate_release_notes: false, + input_make_latest: undefined, + }), + undefined, + ); + }); }); describe('parseConfig', () => { it('parses basic config', () => { diff --git a/src/util.ts b/src/util.ts index ed74e43..6911fd2 100644 --- a/src/util.ts +++ b/src/util.ts @@ -35,10 +35,17 @@ export const uploadUrl = (url: string): string => { }; export const releaseBody = (config: Config): string | undefined => { - return ( - (config.input_body_path && readFileSync(config.input_body_path).toString('utf8')) || - config.input_body - ); + if (config.input_body_path) { + try { + const contents = readFileSync(config.input_body_path, 'utf8'); + return contents; + } catch (err: any) { + console.warn( + `⚠️ Failed to read body_path "${config.input_body_path}" (${err?.code ?? 'ERR'}). Falling back to 'body' input.`, + ); + } + } + return config.input_body; }; type Env = { [key: string]: string | undefined };