diff --git a/src/prompt.copy.test.ts b/src/prompt.copy.test.ts new file mode 100644 index 00000000..c711ab8c --- /dev/null +++ b/src/prompt.copy.test.ts @@ -0,0 +1,18 @@ +import assert from 'node:assert/strict'; + +const test = (name: string, fn: () => void | Promise) => { + Promise.resolve(fn()).then(() => { + console.log(`ok - ${name}`); + }); +}; + +test('clipboard fallback keeps the original error message available to users', () => { + const message = 'Both xsel and fallback failed'; + const output = `Clipboard unavailable. Copy the script manually.\n\n${message}`; + + assert.equal( + output.includes('Clipboard unavailable. Copy the script manually.'), + true + ); + assert.equal(output.includes(message), true); +}); diff --git a/src/prompt.ts b/src/prompt.ts index 145c07b3..fc26d73a 100644 --- a/src/prompt.ts +++ b/src/prompt.ts @@ -198,8 +198,18 @@ async function runOrReviseFlow( label: '📋 ' + i18n.t('Copy'), hint: i18n.t('Copy the generated script to your clipboard'), value: async () => { - await clipboardy.write(script); - p.outro(i18n.t('Copied to clipboard!')); + try { + await clipboardy.write(script); + p.outro(i18n.t('Copied to clipboard!')); + } catch (error) { + const message = + error instanceof Error ? error.message : String(error); + p.outro( + `${i18n.t( + 'Clipboard unavailable. Copy the script manually.' + )}\n\n${message}` + ); + } }, }, {