{"record":{"id":"b26d1b0faa1c8b9a","repo":"pulumi/pulumi","slug":"could-not-read-s-w-b26d1b","errorCode":null,"errorMessage":"could not read %s: %w","messagePattern":"could not read (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/nodejs/npm/manifest.go","lineNumber":42,"sourceCode":")\n\n// PackageManifestNames are the filenames recognized as Node.js package manifests, in priority order. pnpm allows\n// package.yaml as an alternative to package.json (see https://pnpm.io/package_json), and prefers package.json if both\n// exist.\nvar PackageManifestNames = []string{\"package.json\", \"package.yaml\"}\n\n// ReadPackageManifest reads the package manifest (package.json or package.yaml) from dir and returns the parsed\n// contents along with the path of the file that was read. If both files exist, package.json is preferred. Returns an\n// error wrapping os.ErrNotExist if neither file exists in dir.\nfunc ReadPackageManifest(dir string) (map[string]any, string, error) {\n\tfor _, name := range PackageManifestNames {\n\t\tpath := filepath.Join(dir, name)\n\t\tcontent, err := os.ReadFile(path)\n\t\tif err != nil {\n\t\t\tif errors.Is(err, os.ErrNotExist) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\treturn nil, path, fmt.Errorf(\"could not read %s: %w\", path, err)\n\t\t}\n\t\tdata := map[string]any{}\n\t\tif err := unmarshalManifestBytes(name, content, &data); err != nil {\n\t\t\treturn nil, path, fmt.Errorf(\"could not parse %s: %w\", path, err)\n\t\t}\n\t\treturn data, path, nil\n\t}\n\treturn nil, \"\", fmt.Errorf(\"no package.json or package.yaml in %s: %w\", dir, os.ErrNotExist)\n}\n\nfunc unmarshalManifestBytes(name string, content []byte, target any) error {\n\tm, _ := encoding.Detect(name)\n\tif m == nil {\n\t\treturn fmt.Errorf(\"unsupported package manifest extension: %s\", filepath.Ext(name))\n\t}\n\treturn m.Unmarshal(content, target)\n}\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/nodejs/npm/manifest.go#L24-L60","documentation":"ReadPackageManifest tries to os.ReadFile each recognized manifest (package.json, then package.yaml) in the given directory (sdk/nodejs/npm/manifest.go:35-43). Missing files are skipped, but any other read failure — permission denied, the path being a directory, I/O errors — is returned wrapped as \"could not read <path>\". It distinguishes real read failures from the benign not-exist case.","triggerScenarios":"os.ReadFile on <dir>/package.json or <dir>/package.yaml fails with an error other than os.ErrNotExist: the file exists but is unreadable due to permissions, it is a directory named package.json, or a device/symlink I/O error occurs.","commonSituations":"A directory literally named `package.json` exists in the project root; restrictive file permissions after copying a repo as root or on Windows ACL issues; a broken mount or network drive where the manifest lives; SELinux/AppArmor blocking reads in containers.","solutions":["Check permissions on the manifest path (`ls -la <path>`) and fix them (chmod/chown)","If a directory is named package.json or package.yaml, rename or remove it","Verify the file is a regular readable file, not a broken symlink or special file","Run `pulumi` as a user with read access to the project directory"],"exampleFix":"// before\n$ ls -la /app\n-rw------- 1 root root 312 package.json\n// after\n$ sudo chown $(whoami) /app/package.json && chmod 644 /app/package.json","handlingStrategy":"try-catch","validationCode":"info, err := os.Stat(manifestPath)\nif err != nil {\n\treturn fmt.Errorf(\"manifest not stat-able: %w\", err)\n}\nif !info.Mode().IsRegular() {\n\treturn fmt.Errorf(\"%s is not a regular file\", manifestPath)\n}\nf, err := os.Open(manifestPath)\nif err != nil {\n\treturn fmt.Errorf(\"manifest unreadable (check permissions): %w\", err)\n}\nf.Close()","typeGuard":null,"tryCatchPattern":"data, path, err := npm.ReadPackageManifest(dir)\nvar pathErr *os.PathError\nif errors.As(err, &pathErr) && !errors.Is(err, os.ErrNotExist) {\n\t// permission or I/O problem on pathErr.Path\n\tlog.Warnf(\"cannot read manifest %s: %v; check permissions/ownership\", pathErr.Path, err)\n\treturn\n}","preventionTips":["Never create directories named package.json or package.yaml","Check file permissions after copying projects as root or between users","Run pulumi as a user with read access to the project tree","Watch for broken symlinks and network mounts under the project directory"],"tags":["nodejs","filesystem","permissions","package-manifest"],"backgroundTag":"file-read-permission-denied","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}