Skip to content

ISSUE-1734 Add missing configuration warning - #1741

Draft
fbuys wants to merge 1 commit into
troessner:masterfrom
fbuys:fbuys/issue-1734-invalid-config-message
Draft

ISSUE-1734 Add missing configuration warning#1741
fbuys wants to merge 1 commit into
troessner:masterfrom
fbuys:fbuys/issue-1734-invalid-config-message

Conversation

@fbuys

@fbuys fbuys commented Oct 12, 2023

Copy link
Copy Markdown
Contributor

This PR adds a more descriptive error message when users add a detector without configuration. Before this change a NoMethodError exception was raised with an unclear error message. Now we catch this exception and provide a more helpful error message.

A better future option might be add dry-schema.
The current yaml schema validator is outdated and does not seem to have good documentation.

See: #1734

This PR adds a more descriptive error message when users add a detector
without configuration. Before this change a NoMethodError exception was
raised with an unclear error message. Now we catch this exception and
provide a more helpful error message.

A better future option might be add
[dry-schema](https://dry-rb.org/gems/dry-schema/1.13/)

See: troessner#1734

@mvz mvz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is very useful but the error handling should be more in line with the rest of Reek.

Once that's done it should be easy to have some tests for this. This will make the specs pass again.

end
end
rescue NoMethodError
warn_about_missing_configuration(detector) if detectors[detector].nil?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it's better to detect that detector[detector] is nil at the beginning of this block and handle that specific case there.

end
end
rescue NoMethodError
warn_about_missing_configuration(detector) if configuration.nil?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it's better to detect that configuration is nil at the beginning of this block and handle that specific case there.

end
end

def warn_about_missing_configuration(detector)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The way error handling works in Reek is that we raise specific errors throughout the code and then do the warning in lib/reek/cli/application.rb.

We do this, among other reasons, because it allows us to test the error handling code without having warnings appear all over the place during the spec run.

In this case, the error should probably be a Reek::Errors::ConfigFileError. It will be handled here:

rescue Errors::ConfigFileError => error

detectors_configuration.each do |name, configuration|
detector = key_to_smell_detector(name)
self[detector] = (self[detector] || {}).merge configuration
if configuration

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Empty configs should be filtered out earlier on. In fact, if you move the handling of the error, Reek will not run with nil configurations so this condition will no longer be needed.

@mvz

mvz commented Oct 13, 2023

Copy link
Copy Markdown
Collaborator

An alternative solution would be to move to dry-schema immediately.

@troessner

Copy link
Copy Markdown
Owner

Agree with all of @mvz comments so far :)

@fbuys

fbuys commented Nov 6, 2023

Copy link
Copy Markdown
Contributor Author

Making this a WIP PR, waiting on #1749

@fbuys
fbuys marked this pull request as draft November 6, 2023 19:43
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.

3 participants