{"record":{"id":"90d9634de4fa02a5","repo":"chocolatey/choco","slug":"file-specified-is-either-not-found-or-not-a-0-fi","errorCode":null,"errorMessage":"File specified is either not found or not a {0} file. '{1}'","messagePattern":"File specified is either not found or not a (.+?) file\\. '(.+?)'","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/chocolatey/infrastructure.app/services/NugetService.cs","lineNumber":437,"sourceCode":"                config.OutputDirectory ?? _fileSystem.GetCurrentDirectory()\r\n                                ));\r\n        }\r\n\r\n        public virtual string GetPackageFileOrThrow(ChocolateyConfiguration config, string extension)\r\n        {\r\n            Func<IFileSystem, string> getLocalFiles = (fileSystem) =>\r\n                {\r\n                    var filesFound = fileSystem.GetFiles(fileSystem.GetCurrentDirectory(), \"*\" + extension).ToList().OrEmpty();\r\n                    Ensure.That(() => filesFound)\r\n                          .Meets((files) => files.Count() == 1,\r\n                                 (name, value) => { throw new FileNotFoundException(\"No {0} files (or more than 1) were found to build in '{1}'. Please specify the {0} file or try in a different directory.\".FormatWith(extension, _fileSystem.GetCurrentDirectory())); });\r\n\r\n                    return filesFound.FirstOrDefault();\r\n                };\r\n\r\n            var filePath = !string.IsNullOrWhiteSpace(config.Input) ? config.Input : getLocalFiles.Invoke(_fileSystem);\r\n            Ensure.That(() => filePath).Meets((file) => _fileSystem.GetFileExtension(file).IsEqualTo(extension) && _fileSystem.FileExists(file),\r\n                                              (name, value) => { throw new ArgumentException(\"File specified is either not found or not a {0} file. '{1}'\".FormatWith(extension, value)); });\r\n\r\n            return filePath;\r\n        }\r\n\r\n        public virtual void Pack(ChocolateyConfiguration config)\r\n        {\r\n            var nuspecFilePath = GetPackageFileOrThrow(config, PackagingConstants.ManifestExtension);\r\n            ValidateNuspec(nuspecFilePath, config);\r\n\r\n            var nuspecDirectory = _fileSystem.GetFullPath(_fileSystem.GetDirectoryName(nuspecFilePath));\r\n            if (string.IsNullOrWhiteSpace(nuspecDirectory))\r\n            {\r\n                nuspecDirectory = _fileSystem.GetCurrentDirectory();\r\n            }\r\n\r\n            // Use case-insensitive properties like \"nuget pack\".\r\n            var properties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);\r\n\r","sourceCodeStart":419,"sourceCodeEnd":455,"githubUrl":"https://github.com/chocolatey/choco/blob/0d5abdd10cc177a141e69547cad6935b419b6c17/src/chocolatey/infrastructure.app/services/NugetService.cs#L419-L455","documentation":"Thrown as an ArgumentException from GetPackageFileOrThrow when the resolved file path (from config.Input or auto-discovery) does not have the expected extension or does not exist on disk. The Ensure.That call validates both the file extension matches and _fileSystem.FileExists returns true.","triggerScenarios":"Calling GetPackageFileOrThrow with config.Input set to a path that either (a) does not end with the expected extension (e.g., passing a .txt file when .nuspec is expected), or (b) refers to a file that does not exist on disk. The validation runs after the getLocalFiles auto-discovery step.","commonSituations":"A user runs 'choco pack wrongfile.txt' or 'choco pack nonexistent.nuspec'. The file must both exist and have the correct extension. Also triggered by typos in the file name or relative path issues.","solutions":["Verify the file exists at the specified path using 'ls' or 'dir' before running the command.","Ensure the file has the correct extension (.nuspec for pack, .nupkg for related operations).","Use an absolute path to avoid relative path resolution issues.","Check for typos in the file name."],"exampleFix":"// before: file doesn't exist or wrong extension\nchoco pack nonexistent.nuspec   // file not found\nchoco pack readme.txt           // wrong extension\n\n// after: verify and use correct file\nchoco pack C:\\projects\\myapp\\myapp.nuspec","handlingStrategy":"validation","validationCode":"// Before calling GetPackageFileOrThrow, validate the input file\nif (!string.IsNullOrWhiteSpace(config.Input))\n{\n    if (!_fileSystem.FileExists(config.Input))\n    {\n        throw new InvalidOperationException($\"File not found: '{config.Input}'\");\n    }\n    if (!_fileSystem.GetFileExtension(config.Input).IsEqualTo(extension))\n    {\n        throw new InvalidOperationException($\"File '{config.Input}' does not have extension '{extension}'\");\n    }\n}","typeGuard":"public static bool IsValidPackageFile(string filePath, string expectedExtension, IFileSystem fileSystem)\n{\n    return !string.IsNullOrWhiteSpace(filePath)\n        && fileSystem.FileExists(filePath)\n        && fileSystem.GetFileExtension(filePath).IsEqualTo(expectedExtension);\n}","tryCatchPattern":"try\n{\n    var packageFile = _nugetService.GetPackageFileOrThrow(config, extension);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"not found or not a\"))\n{\n    logger.Error($\"Invalid file specified: {ex.Message}. Verify the path and extension.\");\n}","preventionTips":["Verify the file exists at the specified path before running pack.","Ensure the file has the correct extension (.nuspec for pack).","Use absolute paths to avoid relative path resolution issues.","Check for typos in file names and paths."],"tags":["pack","nuspec","file-validation","argument","chocolatey"],"backgroundTag":null,"analyzedSha":"0d5abdd10cc177a141e69547cad6935b419b6c17","analyzedAt":"2026-08-13T18:33:03.301Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}