Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

`socket npm outdated --json` appends an error object after valid JSON when npm exits with code 1

Đang mở
#1,656 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
65/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
node.js, typescript
Lĩnh vực
cli

Hướng nghiên cứu

Start by reading src/commands/npm/cmd-npm.mts (lines 95-119) and src/cli.mts (lines 53-99) to see how subprocess rejection reaches the top-level error handler. Reproduce with socket npm outdated -g --depth=0 --json using an outdated global package. Done means npm's valid JSON and exit status 1 are kept, with no extra error object appended.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Description

When global packages are outdated, socket npm outdated -g --depth=0 --json outputs npm’s valid JSON result, then appends a second JSON object reporting an unexpected error.

The combined stdout cannot be parsed as a single JSON document. npm intentionally returns exit code 1 when updates are available, so this status alone does not indicate an unexpected failure.

Environment
  • Socket CLI: 1.8.4
  • npm: 12.0.2
  • Node.js: 24.18.0
  • macOS: 27.0.1, Apple Silicon
Steps to reproduce

With at least one outdated global npm package, run:

socket npm outdated -g --depth=0 --json

In my environment, npm itself is outdated but intentionally held at its installed version.

Actual behavior
  • Exit code: 1
  • stdout: valid outdated-package JSON, followed by:
{
  "ok": false,
  "message": "Unexpected error",
  "cause": "command failed"
}
  • stderr: empty in the standalone reproduction.

This also reproduces outside the maintenance automation that first exposed it. Socket version/help checks and successful update commands work.

Expected behavior

Preserve npm’s JSON output and exit status without appending a generic error object for the expected “updates available” result.

Investigation

The npm wrapper both awaits spawnPromise and registers an exit handler that waits for telemetry before exiting. A rejected subprocess promise can reach the top-level error handler, which prints the additional JSON object.

This suggests an interaction between subprocess rejection and asynchronous exit handling; it is not a verified root-cause patch.

I compared tags v1.8.4 and v1.10.1. The relevant wrapper, subprocess launcher, telemetry and error-handler files are identical, with unchanged relevant dependency versions. However, the runtime reproduction is on 1.8.4; I have not executed 1.10.1.

For reference, npm 12.2.1 also explicitly sets exit code 1 when outdated packages exist.

Ngôn ngữ chính
TypeScript
Star
336
Fork
72
Merge trung bình
8 giờ 18 phút
Pull request đã merge (30 ngày)
70

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của SocketDev/socket-cli

Tất cả issue của SocketDev/socket-cli

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.