{"record":{"id":"453e936acf654a42","repo":"hashicorp/packer","slug":"failed-to-parse-api-version-from-constraints-s","errorCode":null,"errorMessage":"Failed to parse API Version from constraints: %s","messagePattern":"Failed to parse API Version from constraints: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packer/plugin-getter/plugins.go","lineNumber":525,"sourceCode":"\treturn ver, nil\n}\n\nvar localAPIVersion APIVersion\n\nfunc (binOpts *BinaryInstallationOptions) CheckProtocolVersion(remoteProt string) error {\n\t// no protocol version check\n\tif binOpts.APIVersionMajor == \"\" && binOpts.APIVersionMinor == \"\" {\n\t\treturn nil\n\t}\n\n\tlocalVersion := localAPIVersion\n\tif binOpts.APIVersionMajor != pluginsdk.APIVersionMajor ||\n\t\tbinOpts.APIVersionMinor != pluginsdk.APIVersionMinor {\n\t\tvar err error\n\n\t\tlocalVersion, err = NewAPIVersion(fmt.Sprintf(\"x%s.%s\", binOpts.APIVersionMajor, binOpts.APIVersionMinor))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to parse API Version from constraints: %s\", err)\n\t\t}\n\t}\n\n\tremoteVersion, err := NewAPIVersion(remoteProt)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif localVersion.Major != remoteVersion.Major {\n\t\treturn fmt.Errorf(\"unsupported remote protocol MAJOR version %d. The current MAJOR protocol version is %d.\"+\n\t\t\t\" This version of Packer can only communicate with plugins using that version\", remoteVersion.Major, localVersion.Major)\n\t}\n\n\tif remoteVersion.Minor > localVersion.Minor {\n\t\treturn fmt.Errorf(\"unsupported remote protocol MINOR version %d. The supported MINOR protocol versions are version %d and below. \"+\n\t\t\t\"Please upgrade Packer or use an older version of the plugin if possible\", remoteVersion.Minor, localVersion.Minor)\n\t}\n","sourceCodeStart":507,"sourceCodeEnd":543,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/packer/plugin-getter/plugins.go#L507-L543","documentation":"CheckProtocolVersion() builds the LOCAL protocol version from binOpts.APIVersionMajor/Minor via NewAPIVersion(); if that construction fails (which can only happen if the constraint fields form an invalid version string), it returns this wrapped error. The remote side is parsed separately afterwards.","triggerScenarios":"Calling CheckProtocolVersion with BinaryInstallationOptions whose APIVersionMajor/APIVersionMinor (different from pluginsdk constants) produce a string like \"x\" or \"x5.\" that NewAPIVersion cannot parse.","commonSituations":"Programmatic callers (custom installers/tests) populate APIVersionMajor/Minor with empty strings or non-numeric values instead of numbers like 5 and 0.","solutions":["Leave APIVersionMajor/APIVersionMinor at their defaults (the pluginsdk constants) unless you truly need to override.","If overriding, pass valid numeric major/minor values (e.g. 5 and 0).","Call installOpts.WithDefaultBinaryInstallationOptions() or similar SDK helpers to fill sane defaults before use."],"exampleFix":"// before\nbinOpts := plugingetter.BinaryInstallationOptions{APIVersionMajor: \"\", APIVersionMinor: \"\"}\n// after\nbinOpts.APIVersionMajor, binOpts.APIVersionMinor = pluginsdk.APIVersionMajor, pluginsdk.APIVersionMinor","handlingStrategy":"validation","validationCode":"if binOpts.APIVersionMajor == \"\" || binOpts.APIVersionMinor == \"\" {\n\tbinOpts.APIVersionMajor, binOpts.APIVersionMinor = pluginsdk.APIVersionMajor, pluginsdk.APIVersionMinor\n}","typeGuard":null,"tryCatchPattern":"if err := binOpts.CheckProtocolVersion(entry.ProtVersion); err != nil {\n\tif strings.Contains(err.Error(), \"Failed to parse API Version from constraints\") {\n\t\t// reset binOpts to SDK defaults and retry\n\t}\n}","preventionTips":["Don't override APIVersionMajor/Minor unless required; prefer SDK defaults","Use WithDefaultBinaryInstallationOptions to populate constraints safely","Type the constraint fields as numbers, never empty strings"],"tags":["plugin-getter","protocol-version","constraints","parsing"],"backgroundTag":"invalid-version-string","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}