Fix PhpComposerLock parser error by supporting non-string versions
What does this MR do and why?
Background
The Repository X-Ray scans a project's repository for dependency config files and then parses a list of libraries from the file content. The libraries are then included into the code generation prompt to improve code suggestions. This feature was converted from a CI job to an internal Sidekiq job, and is currently rolled out at 100% in #483928 (closed).
This MR
While monitoring the Sidekiq failed job logs, we noticed the following error:
- json.exception.class:
NoMethodError - json.exception.message:
undefined method `delete_prefix' for 20240308:Integer
This error occurs because delete_prefix is being called on an Integer instead of a String in PhpComposerLock here.
In this MR, we handle the error so that it doesn't bubble up as a Sidekiq job error. Specifically, we:
- Updated
PhpComposerLockparsing logic with atryondelete_prefixso that it doesn't raise an exception. If the value is a non-string, it falls through to the base classsanitize_libsmethod. - Updated the base class
sanitize_libsso that it converts any valid version data type to a string before handling.- It's assumed that a valid version may sometimes be specified as an Integer or Float within structured data formats like
JSON. - Making this change in the base class allows us to cover all config file types where this could occur.
- It's assumed that a valid version may sometimes be specified as an Integer or Float within structured data formats like
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
| Error reproduced locally with new spec test | Spec test passes after change |
|---|---|
![]() |
![]() |
Related to #483928 (closed)

