Skip to content

(trivial) Give notice about invalid modules#3261

Merged
joshcooper merged 2 commits intopuppetlabs:masterfrom
radford:notice-invalid-modules
Nov 14, 2014
Merged

(trivial) Give notice about invalid modules#3261
joshcooper merged 2 commits intopuppetlabs:masterfrom
radford:notice-invalid-modules

Conversation

@radford
Copy link
Contributor

@radford radford commented Oct 31, 2014

Give notice when a module on the modulepath is invalid, explaining why.
To do this cleanly, we stop trying to add "." and ".." as modules since
these are always invalid.

@puppetcla
Copy link

Waiting for CLA signature by @radford

@radford - We require a Contributor License Agreement (CLA) for people who contribute to Puppet, but we have an easy click-through license with instructions, which is available at https://cla.puppetlabs.com/

Note: if your contribution is trivial and you think it may be exempt from the CLA, please post a short reply to this comment with details. http://docs.puppetlabs.com/community/trivial_patch_exemption.html

@puppetcla
Copy link

CLA signed by all contributors.

@kylog
Copy link

kylog commented Oct 31, 2014

@andersonmills please take a look. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Puppet.log_exception(e) is preferred so that if puppet is running with --trace it will show the backtrace leading up to the exception.

@radford radford force-pushed the notice-invalid-modules branch from f1eb86f to 4430b90 Compare November 5, 2014 10:37
@kylog
Copy link

kylog commented Nov 5, 2014

@radford thanks for the contribution! This makes a lot of sense. Can you add a ticket at tickets.puppetlabs.com and reference it in the commit message? (This doesn't meet our criteria for "trivial" since it does change behavior (in a good way) so it'll be nice to have it tracked as a ticket.)

Thanks!!

@hlindberg
Copy link
Contributor

From triage:

  • waiting on ticket to be created by @radford

@ffrank
Copy link
Contributor

ffrank commented Nov 5, 2014

I'd be grateful if the commit message could give some more insight on how this end is achieved.
The diff itself is a little cryptic (to me, that is).

@radford
Copy link
Contributor Author

radford commented Nov 5, 2014

Hi @ffrank and @kylog, I think I can address the triviality and the how at the same time. The patch adds a logging message, which is explicitly covered in TPE Policy and then filters "." and ".." which would otherwise lead to superfluous warnings but were ignored anyway beforehand. There is no practical change other than the addition of a useful warning.

@ffrank
Copy link
Contributor

ffrank commented Nov 5, 2014

I'll admit that I'm a little edgy on the control flow change and I feel it warrants at least some explanation.

While you're at it, could you change the (trivial) tag to (maint)?

Give notice when a module on the modulepath is invalid, explaining why.
To do this cleanly, we stop trying to add "." and ".." as modules since
these are always invalid.
module_references contains Hashes so there is no need to look for
strings within it, especially when the next line does what this one was
supposed to do.
@radford radford force-pushed the notice-invalid-modules branch from 4430b90 to 33c0571 Compare November 8, 2014 00:45
@radford
Copy link
Contributor Author

radford commented Nov 8, 2014

@ffrank, along with changing the tag, I split the patch into three to provide separate motivations for each change.

@ffrank
Copy link
Contributor

ffrank commented Nov 8, 2014

Awesome, thanks!

@andersonmills
Copy link
Contributor

👍

@joshcooper
Copy link
Contributor

@radford thanks for updating the PR. I have a few comments:

  1. Can you update the commit message for radford@33c0571 to describe why Dir.entries.each is less efficient than Dir.foreach?
  2. Looks like a typo in the above commit summary, should be "and less efficient"?
  3. Can you add a test, at least for the case where an exception is raised and logged.

@radford radford force-pushed the notice-invalid-modules branch from 33c0571 to 4430b90 Compare November 11, 2014 01:24
@radford
Copy link
Contributor Author

radford commented Nov 11, 2014

@joshcooper, 1,2) I removed the Dir.foreach commit as it is orthogonal to the fundamental point of this PR. 3) I will not add a test that verifies that an exception is raised and logged. To check that the exception is logged would be to decide that catching this error and continuing is a good idea to begin with and I don't think it is.

@radford radford force-pushed the notice-invalid-modules branch from 4430b90 to 96a82f3 Compare November 11, 2014 01:45
@joshcooper
Copy link
Contributor

@radford I don't follow your logic about, "to check that the exception is logged would be to decide that catching this error and continuing is a good idea to begin with and I don't think it is." We write tests to verify that the system behaves as expected, not whether or not we agree with the behavior.

@ffrank
Copy link
Contributor

ffrank commented Nov 11, 2014

I think there is a misunderstanding here.

"Adding a test" refers to test cases in spec/ for TDD. The test is not supposed to happen in puppet code, which I believe @radford misconstrued.

@radford
Copy link
Contributor Author

radford commented Nov 11, 2014

@ffrank, I understand what you were asking for in a test, but to me tests should check that something is happening the way that it should. @joshcooper, the question is what should happen in this code? What I haven't gleaned from any of your responses is what was this code trying to do? And what should it do?

  • Should it be catching module exceptions to begin with?
  • How many other different places does puppet traverse the module path? (lots)
    • And on how many of those does it check for invalid modules? (none)
    • So what happens when only this case skips invalid modules? (some of a module is loaded)
      • Why would running half a module be good idea? (it's not)

So, @joshcooper, what I'm saying is that I will not enshrine the current behavior in a test because I don't think it is doing the correct thing. I don't know what the correct thing is, but what I am certain about is that hiding the exception is wrong. To that effect this patch is a Band Aid that should be applied while someone thinks about the higher level questions.

@ffrank
Copy link
Contributor

ffrank commented Nov 11, 2014

So you are saying that there is a higher level issue that this change will not solve?

Is there a ticket for that? If no, would you open one?

@joshcooper
Copy link
Contributor

@radford I agree we should not be hiding the exception. Ensuring we log the exception sounds like a good first step, so I am 👍 for this change.

That said, this PR changes the behavior of puppet. Whenever there is a behavior change, we write tests to verify that puppet behaves the way we expect at that point in time. Writing a test doesn't "enshrine" the behavior -- it documents it, and we are free to change the behavior in the future. We simply update the code and the tests to match the new behavior.

Meanwhile, we should discuss what the new behavior should be on puppet-dev, or if you have ideas about what it should be, please file a ticket as @ffrank suggested, and write up how you think it should work.

The module loading code is invoked in many different contexts, especially with the new environments work going on between 3.5-3.7. I have not made any suggestions about how this should work, because I am not current on how environments interact with modules.

@hlindberg
Copy link
Contributor

Triage Notes:

  • @joshcooper to write a test and merge
  • A ticket should be created for a more long term solution to the problem of "invalid modules"
  • @hlindberg to add ticket

@joshcooper joshcooper merged commit 96a82f3 into puppetlabs:master Nov 14, 2014
@joshcooper
Copy link
Contributor

Btw, there is already a ticket filed about puppet's lack of debugging when a module has invalid metadata, https://tickets.puppetlabs.com/browse/PUP-3664

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.