voxpupuli / voxpupuli/puppet-php

phpversion fact may come out empty

Open Beginner friendly
#769 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Puppet
Stars
86
Forks
264
Avg merge
29m
Merged PRs (30d)
1

Description

Disclaimer: AI-generated text below the line, generated by Claude Opus 5. The issue was found (by Claude) while working with pull request https://github.com/voxpupuli/puppet-php/pull/768

Having the AI generate issues is cheap, reading and understanding them is not. I respect that some maintainers may want to close AI-generated issues without spending time on explaining why.


Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: openvox 8 (Gemfile range >= 7, < 9)
  • Ruby: 3.4.10
  • Facter: 5.7.0
  • Distribution: any
  • Module version: master (12.0.1-rc0)

How to reproduce (e.g Puppet code you use)

The fact parses the first line of php -v only:

https://github.com/voxpupuli/puppet-php/blob/master/lib/facter/phpversion.rb

A php that emits a startup warning writes it to stdout before the version banner. A php on $PATH behaving like this is enough:

#!/bin/sh
echo "PHP Warning:  Module 'imagick' already loaded in Unknown on line 0"
echo "PHP 8.2.7 (cli) (built: Jun  8 2023 20:03:25) (NTS)"
echo "Copyright (c) The PHP Group"

What are you seeing

php on PATH: "/.../php"
php -v first line: "PHP Warning:  Module 'imagick' already loaded in Unknown on line 0"
phpversion fact:   nil

The fact resolves to nothing, silently — no version, no warning, no error in the log. Anything keying on $facts['phpversion'] sees an absent fact on a node where php is installed and working.

What behaviour did you expect instead

8.2.7, as on a node whose php starts cleanly. Scanning the whole output rather than the first line would do it, e.g. output[%r{^PHP (\d+\.\d+\.\d+\S*)}, 1] (^ is already per-line in Ruby).

Output log

No log output at all — that is part of the problem; the failure is silent.

Any additional information you'd like to impart

Pre-existing and unrelated to https://github.com/voxpupuli/puppet-php/pull/768, which is about the fact raising when php is absent; that PR does not touch the parsing.

Two smaller things noticed in the same line, not worth their own issues:

  • An RC build reports as 8.4.0RC1, since the match keeps the whole token. Probably wanted, but worth knowing.
  • The regex %r{^(?:(\d+)\.)(?:(\d+)\.)?(\*|\d+)} has three capture groups nothing reads, and the \* alternative cannot match php -v output.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/facter/phpversion.rb and reproduce the fact using a php executable that prints a warning before its version banner. Update the parsing so the version is found in the command output and verify that the phpversion fact reports 8.2.7 instead of nil; add or update regression coverage in the fact tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, ruby
Domain
devops
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.