Skip to content

Fix PhpComposerLock parser error by supporting non-string versions

Leaminn Ma requested to merge fix-delete-prefix-error-config-file-parser into master

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.

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 PhpComposerLock parsing logic with a try on delete_prefix so that it doesn't raise an exception. If the value is a non-string, it falls through to the base class sanitize_libs method.
  • Updated the base class sanitize_libs so 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.

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
Screenshot_2024-10-23_at_11.44.15_AM Screenshot_2024-10-23_at_12.44.13_PM

Related to #483928

Edited by Leaminn Ma

Merge request reports

Loading