Skip to content

Commit e405e81

Browse files
committed
fix(error-handling): improve network error diagnostics and lock timeout messages
- Enhanced HTTP request/download error handling with specific network diagnostics (ENOTFOUND, ECONNREFUSED, ETIMEDOUT, ECONNRESET) - Improved download lock timeout error to include PID tracking, lock age, resource URL, and actionable resolution steps - All error messages now provide clear context and guidance for troubleshooting
1 parent eed69ed commit e405e81

2 files changed

Lines changed: 51 additions & 9 deletions

File tree

src/download-lock.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,16 @@ async function acquireLock(
121121
} else {
122122
// Lock is valid, check timeout
123123
if (Date.now() - startTime > lockTimeout) {
124+
const lockAge = Date.now() - lockInfo.startTime
124125
throw new Error(
125-
`Lock acquisition timed out after ${lockTimeout}ms (held by PID ${lockInfo.pid})`,
126+
`Download lock timed out after ${lockTimeout}ms\n` +
127+
`Lock held by process ${lockInfo.pid} for ${lockAge}ms\n` +
128+
`Resource: ${lockInfo.url}\n` +
129+
`Started: ${new Date(lockInfo.startTime).toISOString()}\n` +
130+
'To resolve:\n' +
131+
` 1. Check if process ${lockInfo.pid} is still running: ps -p ${lockInfo.pid}\n` +
132+
` 2. If stale, remove lock file: rm "${lockPath}"\n` +
133+
' 3. Or increase lockTimeout option',
126134
)
127135
}
128136

src/http-request.ts

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,27 @@ async function httpRequestAttempt(
601601
)
602602

603603
request.on('error', (error: Error) => {
604-
const err = new Error(`HTTP request failed: ${error.message}`, {
605-
cause: error,
606-
})
607-
reject(err)
604+
const code = (error as NodeJS.ErrnoException).code
605+
let message = `HTTP request failed for ${url}: ${error.message}\n`
606+
607+
if (code === 'ENOTFOUND') {
608+
message +=
609+
'DNS lookup failed. Check the hostname and your network connection.'
610+
} else if (code === 'ECONNREFUSED') {
611+
message +=
612+
'Connection refused. Verify the server is running and accessible.'
613+
} else if (code === 'ETIMEDOUT') {
614+
message +=
615+
'Request timed out. Check your network or increase the timeout value.'
616+
} else if (code === 'ECONNRESET') {
617+
message +=
618+
'Connection reset. The server may have closed the connection unexpectedly.'
619+
} else {
620+
message +=
621+
'Check your network connection and verify the URL is correct.'
622+
}
623+
624+
reject(new Error(message, { cause: error }))
608625
})
609626

610627
request.on('timeout', () => {
@@ -811,10 +828,27 @@ async function httpDownloadAttempt(
811828

812829
request.on('error', (error: Error) => {
813830
closeStream()
814-
const err = new Error(`HTTP download failed: ${error.message}`, {
815-
cause: error,
816-
})
817-
reject(err)
831+
const code = (error as NodeJS.ErrnoException).code
832+
let message = `HTTP download failed for ${url}: ${error.message}\n`
833+
834+
if (code === 'ENOTFOUND') {
835+
message +=
836+
'DNS lookup failed. Check the hostname and your network connection.'
837+
} else if (code === 'ECONNREFUSED') {
838+
message +=
839+
'Connection refused. Verify the server is running and accessible.'
840+
} else if (code === 'ETIMEDOUT') {
841+
message +=
842+
'Request timed out. Check your network or increase the timeout value.'
843+
} else if (code === 'ECONNRESET') {
844+
message +=
845+
'Connection reset. The server may have closed the connection unexpectedly.'
846+
} else {
847+
message +=
848+
'Check your network connection and verify the URL is correct.'
849+
}
850+
851+
reject(new Error(message, { cause: error }))
818852
})
819853

820854
request.on('timeout', () => {

0 commit comments

Comments
 (0)