fresh-cat-90827
06/18/2023, 11:57 AMfresh-cat-90827
06/18/2023, 11:57 AMDependencyRuleActionDeniedError
if there are visibility violations or UnownedDependencyError
if Pants cannot infer owners for some imports.
Not every user is going to be closely familiar with the error and their meaning. Most likely, Pants admins will have some internal documentation / troubleshooting guide tailored to the engineering organization jargon / context. So what I'd like to do is to print in the console an epilogue message depending on the error raised. I've experimented with the plugins model, but can't seem to find a way to post-process a failure raised by a rule.fresh-cat-90827
06/18/2023, 11:58 AM❯ pants dependencies ::
12:44:06.76 [ERROR] 1 Exception encountered:
Engine traceback:
in `dependencies` goal
DependencyRuleActionDeniedError: cheeseshop/cli/utils/utils.py has 1 dependency violation:
* cheeseshop/cli/utils/BUILD[!*] -> cheeseshop/repository/parsing : DENY
python_sources cheeseshop/cli/utils/utils.py -> python_sources cheeseshop/repository/parsing/casts.py
--------------------------------------------------------------------------------------------------------------
To learn more about the visibility rules violations, please see <https://mycompany.org/development-guidelines/pants#visibility>.
bitter-ability-32190
06/18/2023, 12:30 PMbitter-ability-32190
06/18/2023, 12:31 PMfresh-cat-90827
06/18/2023, 12:36 PMYou could likely monkeypatch the type in your pluginI am sorry, could you please provide an example? I don't think I understand how this would be used in a rule
curved-television-6568
06/19/2023, 2:41 PMasync def some_rule() -> RetType:
try:
await Get(...)
except (IntrinsicError, ...) as e:
log.error("Bam")
return ...
fresh-cat-90827
06/19/2023, 2:42 PMcurved-television-6568
06/19/2023, 2:43 PMfresh-cat-90827
06/19/2023, 2:49 PMbitter-ability-32190
06/19/2023, 3:21 PMrules
body, monkeypatch the exception type to append your special message when initializedfresh-cat-90827
06/19/2023, 3:45 PMclass MyExc(DependencyRulesError):
def __call__(self, *args, **kwargs):
1/0
@rule
def epilogue_visibility_error() -> ???:
from pants.engine.internals import dep_rules
dep_rules.DependencyRuleActionDeniedError = MyExc
@curved-television-6568, do you know what return type my rule will have so that it's guaranteed to be executed when evaluating the dependencies?bitter-ability-32190
06/19/2023, 3:45 PMdef rules()
😉curved-television-6568
06/19/2023, 3:46 PMcurved-television-6568
06/19/2023, 3:47 PMfresh-cat-90827
06/19/2023, 3:48 PMSo I suggest putting it insideI see it's being called, just need to confirm that I can keep the parts that are there and only extend with extra behaviordef rules()
fresh-cat-90827
06/19/2023, 4:49 PMfrom pants.engine import target
class DependencyRuleActionDeniedError(Exception):
@classmethod
def create(cls, description_of_origin: str) -> 'DependencyRuleActionDeniedError':
return cls(f"Dependency rule violation for {description_of_origin}")
def __init__(self, message):
super(DependencyRuleActionDeniedError, self).__init__(message + "\n\n" + epilogue_visibility_violation())
target.DependencyRuleActionDeniedError = DependencyRuleActionDeniedError
return collect_rules()
yields
$ ./pants --no-pantsd dependencies ::
17:47:23.58 [ERROR] 1 Exception encountered:
Engine traceback:
in `dependencies` goal
DependencyRuleActionDeniedError: cheeseshop/cli/utils/utils.py has 1 dependency violation:
* cheeseshop/cli/utils/BUILD[!*] -> cheeseshop/repository/parsing : DENY
python_sources cheeseshop/cli/utils/utils.py -> python_sources cheeseshop/repository/parsing/casts.py
------------------------------------------------------
To learn how to fix visibility rules violations, visit
<https://org.com/pants-url-help>
------------------------------------------------------
thanks very much Joshua and Andreas!bitter-ability-32190
06/19/2023, 4:50 PMfresh-cat-90827
06/19/2023, 4:50 PMfresh-cat-90827
06/19/2023, 4:50 PMcurved-television-6568
06/19/2023, 6:03 PM