-
Notifications
You must be signed in to change notification settings - Fork 98
fix: ignore npm registry 404 status response on sync process #740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -228,7 +228,7 @@ | |||||||||
| const { status, data } = remoteFetchResult; | ||||||||||
|
|
||||||||||
| // deleted or blocked | ||||||||||
| if (status === 404 || status === 451) { | ||||||||||
| if (status === 451) { | ||||||||||
| return true; | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -245,6 +245,23 @@ | |||||||||
|
|
||||||||||
| // security holder | ||||||||||
| // test/fixtures/registry.npmjs.org/security-holding-package.json | ||||||||||
| // { | ||||||||||
| // "_id": "xxx", | ||||||||||
| // "_rev": "9-a740a77bcd978abeec47d2d027bf688c", | ||||||||||
| // "name": "xxx", | ||||||||||
| // "time": { | ||||||||||
| // "modified": "2017-11-28T00:45:24.162Z", | ||||||||||
| // "created": "2013-09-20T23:25:18.122Z", | ||||||||||
| // "0.0.0": "2013-09-20T23:25:20.242Z", | ||||||||||
| // "1.0.0": "2016-06-22T00:07:41.958Z", | ||||||||||
| // "0.0.1-security": "2016-12-15T01:03:58.663Z", | ||||||||||
| // "unpublished": { | ||||||||||
| // "time": "2017-11-28T00:45:24.163Z", | ||||||||||
| // "versions": [] | ||||||||||
| // } | ||||||||||
| // }, | ||||||||||
| // "_attachments": {} | ||||||||||
| // } | ||||||||||
| let isSecurityHolder = true; | ||||||||||
| for (const versionInfo of Object.entries<{ _npmUser?: { name: string } }>(data.versions || {})) { | ||||||||||
| const [ v, info ] = versionInfo; | ||||||||||
|
|
@@ -455,6 +472,19 @@ | |||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if (status === 404) { | ||||||||||
| // ignore 404 status | ||||||||||
| // https://github.com/node-modules/detect-port/issues/57 | ||||||||||
| task.error = `Package not found, status 404, data: ${JSON.stringify(data)}`; | ||||||||||
| logs.push(`[${isoNow()}] ❌ ${task.error}, log: ${logUrl}`); | ||||||||||
| logs.push(`[${isoNow()}] ❌ Synced ${fullname} fail, ${task.error}, log: ${logUrl}`); | ||||||||||
| logs.push(`[${isoNow()}] ❌❌❌❌❌ ${fullname} ❌❌❌❌❌`); | ||||||||||
| this.logger.info('[PackageSyncerService.executeTask:fail-request-error] taskId: %s, targetName: %s, %s', | ||||||||||
| task.taskId, task.targetName, task.error); | ||||||||||
| await this.taskService.finishTask(task, TaskState.Fail, logs.join('\n')); | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| let readme = data.readme || ''; | ||||||||||
| if (typeof readme !== 'string') { | ||||||||||
| readme = JSON.stringify(readme); | ||||||||||
|
|
@@ -545,9 +575,9 @@ | |||||||||
| task.error = `invalid maintainers: ${JSON.stringify(maintainers)}`; | ||||||||||
| logs.push(`[${isoNow()}] ❌ ${task.error}, log: ${logUrl}`); | ||||||||||
| logs.push(`[${isoNow()}] ${failEnd}`); | ||||||||||
| await this.taskService.finishTask(task, TaskState.Fail, logs.join('\n')); | ||||||||||
| this.logger.info('[PackageSyncerService.executeTask:fail-invalid-maintainers] taskId: %s, targetName: %s, %s', | ||||||||||
| task.taskId, task.targetName, task.error); | ||||||||||
| await this.taskService.finishTask(task, TaskState.Fail, logs.join('\n')); | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -575,9 +605,9 @@ | |||||||||
| task.error = 'There is no available specific versions, stop task.'; | ||||||||||
| logs.push(`[${isoNow()}] ${task.error}, log: ${logUrl}`); | ||||||||||
| logs.push(`[${isoNow()}] ❌❌❌❌❌ ${fullname} ❌❌❌❌❌`); | ||||||||||
| await this.taskService.finishTask(task, TaskState.Fail, logs.join('\n')); | ||||||||||
| this.logger.info('[PackageSyncerService.executeTask:fail-empty-list] taskId: %s, targetName: %s, %s', | ||||||||||
| task.taskId, task.targetName, task.error); | ||||||||||
| await this.taskService.finishTask(task, TaskState.Fail, logs.join('\n')); | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| if (specificVersions) { | ||||||||||
|
|
@@ -764,9 +794,9 @@ | |||||||||
| logs.push(`[${isoNow()}] ❌ All versions sync fail, package not exists, log: ${logUrl}`); | ||||||||||
| logs.push(`[${isoNow()}] ${failEnd}`); | ||||||||||
| task.error = lastErrorMessage; | ||||||||||
| await this.taskService.finishTask(task, TaskState.Fail, logs.join('\n')); | ||||||||||
| this.logger.info('[PackageSyncerService.executeTask:fail] taskId: %s, targetName: %s, package not exists', | ||||||||||
| task.taskId, task.targetName); | ||||||||||
| await this.taskService.finishTask(task, TaskState.Fail, logs.join('\n')); | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -924,8 +954,8 @@ | |||||||||
| logs.push(`[${isoNow()}] 📝 Log URL: ${logUrl}`); | ||||||||||
| logs.push(`[${isoNow()}] 🔗 ${url}`); | ||||||||||
| task.error = lastErrorMessage; | ||||||||||
| await this.taskService.finishTask(task, TaskState.Success, logs.join('\n')); | ||||||||||
| this.logger.info('[PackageSyncerService.executeTask:success] taskId: %s, targetName: %s', | ||||||||||
| task.taskId, task.targetName); | ||||||||||
| await this.taskService.finishTask(task, TaskState.Success, logs.join('\n')); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure task completion state reflects success The task is finished with Verify if the task should be marked as failed: - await this.taskService.finishTask(task, TaskState.Success, logs.join('\n'));
+ const hasSyncedVersions = updateVersions.length > 0;
+ const taskState = hasSyncedVersions ? TaskState.Success : TaskState.Fail;
+ await this.taskService.finishTask(task, taskState, logs.join('\n'));📝 Committable suggestion
Suggested change
|
||||||||||
| } | ||||||||||
| } | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align
404status handling with PR objectivesCurrently, when a
404status is encountered, the task is marked as failed, and the process exits. According to the PR objectives,404responses from the npm registry during maintenance should be ignored to prevent unnecessary deletions. Instead of failing the task, consider logging the information and proceeding without marking the task as failed.Apply the following diff to adjust the handling:
if (status === 404) { // ignore 404 status // https://github.com/node-modules/detect-port/issues/57 - task.error = `Package not found, status 404, data: ${JSON.stringify(data)}`; - logs.push(`[${isoNow()}] ❌ ${task.error}, log: ${logUrl}`); - logs.push(`[${isoNow()}] ❌ Synced ${fullname} fail, ${task.error}, log: ${logUrl}`); - logs.push(`[${isoNow()}] ❌❌❌❌❌ ${fullname} ❌❌❌❌❌`); - this.logger.info('[PackageSyncerService.executeTask:fail-request-error] taskId: %s, targetName: %s, %s', - task.taskId, task.targetName, task.error); - await this.taskService.finishTask(task, TaskState.Fail, logs.join('\n')); - return; + logs.push(`[${isoNow()}] ⚠️ Package not found (404), but ignoring as per maintenance handling.`); + // Continue processing without marking the task as failed + await this.taskService.appendTaskLog(task, logs.join('\n')); + logs = []; }