Skip to content

Raise ArgumentError when nil settings passed to some methods#790

Open
alstrocrack wants to merge 10 commits into
SAML-Toolkits:masterfrom
alstrocrack:fix-comments
Open

Raise ArgumentError when nil settings passed to some methods#790
alstrocrack wants to merge 10 commits into
SAML-Toolkits:masterfrom
alstrocrack:fix-comments

Conversation

@alstrocrack
Copy link
Copy Markdown

@alstrocrack alstrocrack commented May 3, 2026

Status

READY

Migrations

NO

Description

Several methods across OneLogin::RubySaml::Authrequest, Logoutrequest, SloLogoutresponse, and Metadata accepted nil as their settings argument according to YARD comments ([OneLogin::RubySaml::Settings|nil]), but in practice passing nil causes a NoMethodError immediately when the method tries to call methods on settings.

This PR:

  • Adds an explicit ArgumentError guard at the top of each affected public method, providing a clear error message instead of a cryptic NoMethodError
  • Corrects the YARD @param annotations to remove |nil, accurately reflecting that nil is not a valid value
  • Removes the dead-code private method encode_raw_saml from SamlMessage

ArgumentError was chosen over the library's custom SettingError because passing nil is a caller-side programming error (wrong argument), whereas SettingError is reserved for cases where a settings object exists but contains invalid or missing configuration values.

Related PRs

N/A

Todos

  • Tests
  • Documentation

Deploy Notes

N/A

Steps to Test or Reproduce

N/A

Impacted Areas in Application

  • Authrequest#create, #create_params, #create_authentication_xml_doc
  • Logoutrequest#create, #create_params, #create_logout_request_xml_doc
  • SloLogoutresponse#create, #create_params, #create_logout_response_xml_doc
  • Metadata#generate

@alstrocrack alstrocrack changed the title Fix comments Correct YARD comments to reflect that settings param cannot be nil May 3, 2026
@alstrocrack alstrocrack marked this pull request as ready for review May 3, 2026 08:25
@pitbulk
Copy link
Copy Markdown
Collaborator

pitbulk commented May 14, 2026

@alstrocrack, can you extend the review to other classes? Please add guardrails as well to avoid the NoMethodError errors, thanks!

# @param settings [OneLogin::RubySaml::Settings|nil] Toolkit settings
# @return [String] The deflated and encoded SAML Message (encoded if the compression is requested)
#
def encode_raw_saml(saml, settings)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I found this dead code. What do you think about me deleting this code because I thought it was related to these changes? As far as I checked, this code isn’t called from anywhere and is a private method.

@alstrocrack alstrocrack changed the title Correct YARD comments to reflect that settings param cannot be nil Raise ArgumentError when nil settings passed to builder methods May 23, 2026
@alstrocrack alstrocrack changed the title Raise ArgumentError when nil settings passed to builder methods Raise ArgumentError when nil settings passed to methods May 23, 2026
@alstrocrack
Copy link
Copy Markdown
Author

alstrocrack commented May 23, 2026

@pitbulk

I added some changes to this PR. I searched for incorrect comments regarding nil settings across this repo and fixed all of them.

I thought ArgumentError was more appropriate than SettingsError, so I used ArgumentError. However, I initially suggested using SettingsError as a nil guard error.

I also found some other places where similar nil guard fixes could be applied. However, since this PR was originally intended only to fix comments, I limited the changes to the sources related to those comments for now.

Could you check these changes again?

@alstrocrack alstrocrack changed the title Raise ArgumentError when nil settings passed to methods Raise ArgumentError when nil settings passed to some methods May 23, 2026
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.

2 participants