Puppetfile and module hover fails to fetch forge information due to incorrect API call URL
What Versions are you running?
OS Version: Windows 11 VSCode Version: Version: 1.87.2 (system setup) Puppet Extension Version: 1.5.2 PDK Version: 3.0.1
What You Are Seeing?
Hovering over Puppefile mod line shows nothing and there are errors from the extension and Forge API call (HTTP error 404). The relevant module does exist and after looking into this, it seems the Forge API call ends up using incorrect URL. Example of problematic Puppetfile line:
mod 'puppetlabs/stdlib', '6.6.0'
Issue seems to come from here:
https://github.com/puppetlabs/puppet-vscode/blob/e6f04841b473ef5e1ed699f8e27df450bd440298/src/feature/PuppetfileHoverFeature.ts#L30-L38
The multiple replace-lines try to convert Puppetfile mod-line into title line, which is then used for a Forge API call. Unfortunately, it seems to miss something important. Namely, converting a '/' into a '-' in the mod name. I've tested that converting that manually fixes the issue but more correct fix would be adding a .replace('/', '-') conversion as well.
What is Expected?
Hover should show module information retrieved from forge.
Output Log
Puppet output:
ERROR: 2024-03-16T14:27:23.504Z Error getting Puppet forge data: AxiosError: Request failed with status code 404
Extension host output:
2024-03-16 16:27:23.505 [error] [puppet.puppet-vscode] provider FAILED
2024-03-16 16:27:23.505 [error] TypeError: Cannot read properties of undefined (reading 'name')
at buildMarkdown (c:\Users\x\.vscode\extensions\puppet.puppet-vscode-1.5.2\out\forge.js:13:32)
at PuppetfileHoverProvider.<anonymous> (c:\Users\x\.vscode\extensions\puppet.puppet-vscode-1.5.2\out\feature\PuppetfileHoverFeature.js:43:56)
at Generator.next (<anonymous>)
at fulfilled (c:\Users\x\.vscode\extensions\puppet.puppet-vscode-1.5.2\out\feature\PuppetfileHoverFeature.js:5:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Lookes like similar issue affects module hover information as well but it does seem to do the '/' to '-' conversion already.
Puppet debug log shows:
DEBUG: 2024-03-16T15:13:24.820Z Metadata hover info found puppetlabs module
ERROR: 2024-03-16T15:13:25.055Z Error getting Puppet forge data: AxiosError: Request failed with status code 400
So it seems the issue here is that that it doesn't extract the full module name.
@tmannerm thanks for raising this. You're right, this has definitely been an oversight (I'm surprised it took this long to be found!) So take an example Puppetfile like below:
forge 'https://forge.puppet.com'
mod 'puppetlabs-stdlib'
That will work, But
mod 'puppetlabs/stdlib'
that wont.
You're right in locating where the fix should be, and it should be a relatively simple fix to implement. Do you want to submit a PR to fix this? Otherwise I will try get looking at this when I can, but I can't say when that will be just yet.
Thanks again for raising this!