Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress Warnings from CombinePDF in CI #16705

Merged
merged 6 commits into from
May 14, 2024

Conversation

stevenjcumming
Copy link
Contributor

@stevenjcumming stevenjcumming commented May 9, 2024

Summary

CombinePDF logs a warning "Couldn't connect reference for..." when NULL objects have empty values. NULL objects do not necessarily indicate that there is an error hence the warning. source

In order to reduce the log output in CI the warning is suppressed. Even if there is an error, the test itself will catch this.

Tasks

  • If ENV['CI'] is true, suppress CombinePDF warning.

Related issue(s)

Testing done

  • unit testing modules/claims_api and modules/simple_forms_api`
  • manual examination of combined/generated pdf

What areas of the site does it impact?

  • modules/claims_api
  • modules/simple_forms_api

Acceptance Criteria

  • PDF is still generated and combined
  • RSpec log output doesn't contain the warning if CI=true
  • RSpec log output does contain the warning if CI=false or not present
  • Exceptions still result in failing tests

@@ -106,13 +106,20 @@ def stringify_address(address)
def combine_pdf(id, page1_path, page2_path, page3_path, page4_path)
output_path = "/tmp/#{id}_final.pdf"

# Temporarily suppress CombinePDF warning in CI
# Couldn't connect reference for ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we determined the root cause here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds innocuous. Should we just ignore it everywhere?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I'm not on y'all's team but I've also been researching the cause of these messages. This is the most pertinent conversation/documentation I've been able to find on the topic. From what they can tell, the cause is most likely different PDF authoring tools assigning NULL objects. The warnings happen in case this in unintentional.

boazsegev/combine_pdf#15

Here is the exact line that appears to be setting the warning:

https://github.com/boazsegev/combine_pdf/blob/master/lib/combine_pdf/parser.rb#L664

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Root cause: there's NULL objects. The raw data may not contain some information such as an apartment number, so when it's transformed to "page data" there's nil values:

:"F[0].Page_1[0].Claimants_MailingAddress_ApartmentOrUnitNumber[1]"=>nil,

Also by temporarily I meant the suppression is limited to the #combine_pdf method. Poor wording on my part.

@nihil2501
Copy link
Contributor

nihil2501 commented May 10, 2024

@stevenjcumming Rather than manipulate the global variable, could we instead prepend a warn method in modules/claims_api/config/initializers?

if ENV['CI'] == 'true'
  CombinePDF::PDFParser.prepend(Module.new do
    SUPPRESSIBLE_WARNING = "Couldn't connect reference for"

    def warn(*msgs, **)
      msgs.reject! { _1.start_with? SUPPRESSIBLE_WARNING }
      super
    end
  end)
end

Is this warning always suppressible no matter who uses this library, or only in the exact three places you patched?
If so, I find this warning distracting in my local test environment too. Could we also suppress it there?

Thanks for addressing this!

@stevenjcumming
Copy link
Contributor Author

@stevenjcumming Rather than manipulate the global variable, could we instead prepend a warn method in modules/claims_api/config/initializers?

if ENV['CI'] == 'true'
  CombinePDF::PDFParser.prepend(Module.new do
    SUPPRESSIBLE_WARNING = "Couldn't connect reference for"

    def warn(*msgs, **)
      msgs.reject! { _1.start_with? SUPPRESSIBLE_WARNING }
      super
    end
  end)
end

Is this warning always suppressible no matter who uses this library, or only in the exact three places you patched? If so, I find this warning distracting in my local test environment too. Could we also suppress it there?

Thanks for addressing this!

@nihil2501 I thought it might be better to keep this more visible since it's kind of random and I don't like surprise patches. But I'm open to other approaches especially if it's what your team prefers. My only goal was to reduce the logs in CI.

I don't think the warning should always be suppressed because it could indicate an issue. But as long as the PDF itself is checked against a good copy I think it's okay to suppress in a test environment. I will update the PR with your approach.

@nihil2501
Copy link
Contributor

nihil2501 commented May 10, 2024

@nihil2501 I thought it might be better to keep this more visible since it's kind of random and I don't like surprise patches. But I'm open to other approaches especially if it's what your team prefers. My only goal was to reduce the logs in CI.

I don't think the warning should always be suppressed because it could indicate an issue. But as long as the PDF itself is checked against a good copy I think it's okay to suppress in a test environment. I will update the PR with your approach.

@stevenjcumming How about using refinements in just those files to apply the patch explicitly locally rather than unexplicitly globally? It'd be the first time I've ever used Ruby refinements personally.

module CombinePDF
  class PDFParser
    module WithWarningSuppressed
      MESSAGE = "Couldn't connect reference for"

      if ENV['CI'] == 'true'
        refine module_parent do
          def warn(*messages, **)
            messages.reject! { _1.start_with? MESSAGE }
            super
          end
        end
      end
    end
  end
end

parser = CombinePDF::PDFParser.new('')
parser.send(:warn, "Couldn't connect reference for", "hi")
# => Couldn't connect reference for
# => hi

using CombinePDF::PDFParser::WithWarningSuppressed
parser.send(:warn, "Couldn't connect reference for", "hi")
# => hi

@va-vsp-bot
Copy link
Collaborator

Error: A file (or its parent directories) does not have a CODEOWNERS entry. Please update the .github/CODEOWNERS file and add the entry for the Offending file: config/initializers/combine_pdf_log_patch.rb

@stevenjcumming
Copy link
Contributor Author

@stevenjcumming How about using refinements in just those files to apply the patch explicitly locally rather than unexplicitly globally? It'd be the first time I've ever used Ruby refinements personally.

I think it's fine considering the potential impact is low. If someone wants to change it in the future that's fine with me.

@ericboehs
Copy link
Contributor

I think we should patch this everywhere, not just CI/test. A large cost in DD is superfluous logs.

Is there a reason we should keep this in other places besides test? Perhaps we'd want it in dev but not test/prod (e.g. unless Rails.env.development?)

@stevenjcumming stevenjcumming merged commit 7a52ab2 into master May 14, 2024
19 checks passed
@stevenjcumming stevenjcumming deleted the sjc-suppress-combine_pdf-warning-in-ci branch May 14, 2024 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants