Skip to content

Commit 0b0cfb6

Browse files
committed
fix: preserve original publish error
1 parent ca18086 commit 0b0cfb6

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

cli/src/npm-client.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ export async function packageInit(
574574

575575
const tempDirPath = await mkdtemp(join(tmpdir(), 'npmx-init-'))
576576

577+
let publishResult: NpmExecResult | null = null
578+
let publishError: unknown = null
579+
577580
try {
578581
// Determine access type based on whether it's a scoped package
579582
const isScoped = name.startsWith('@')
@@ -621,8 +624,29 @@ export async function packageInit(
621624
logError(result.stderr.split('\n')[0] || 'Command failed')
622625
}
623626

624-
return result
625-
} finally {
627+
publishResult = result
628+
} catch (error) {
629+
publishError = error
630+
}
631+
632+
try {
626633
await rm(tempDirPath, { recursive: true, force: true })
634+
} catch (cleanupError) {
635+
if (publishError) {
636+
// Preserve original error
637+
Object.assign(cleanupError as Error, { cause: publishError })
638+
}
639+
640+
throw cleanupError
641+
}
642+
643+
if (publishError) {
644+
throw publishError
627645
}
646+
647+
if (!publishResult) {
648+
throw new Error('packageInit completed without a publish result')
649+
}
650+
651+
return publishResult
628652
}

0 commit comments

Comments
 (0)