Actions
Feature #23266
closedHammer should try to fetch new apidoc when resource wasn't found
Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Hammer core
Target version:
-
Description
Currently when hammer doesn't find the requested resource in the apidoc it fails with:
NoMethodError (undefined method `resource' for HammerCLI::MainCommand:Class): /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.pre.develop/lib/hammer_cli/apipie/resource.rb:10:in `resource' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.pre.develop/lib/hammer_cli/apipie/command.rb:41:in `help' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.pre.develop/lib/hammer_cli/exception_handler.rb:78:in `handle_help_wanted' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.pre.develop/lib/hammer_cli/exception_handler.rb:31:in `handle_exception' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.pre.develop/lib/hammer_cli/messages.rb:26:in `handle_exception' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.pre.develop/lib/hammer_cli/abstract.rb:32:in `rescue in run' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.pre.develop/lib/hammer_cli/abstract.rb:28:in `run' /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/subcommand/execution.rb:11:in `execute' /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/command.rb:63:in `run' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.pre.develop/lib/hammer_cli/abstract.rb:29:in `run' /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/command.rb:132:in `run' /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-0.13.pre.develop/bin/hammer:143:in `<top (required)>' /usr/bin/hammer:22:in `load' /usr/bin/hammer:22:in `<main>'This can happen:
- in development
- when a hammer developer used wrong resource name
- when the resource hame has changed in the apidoc and hammer hasn't been updated yet
- in production
- when a hammer plugin has been installed without the appropriate server side plugin
- when a new server side plugin has been installed and hammer hasn't fetched new apidoc yet (usually because user is still trying the same command that fails and therefore it doesn't trigger any api request and cannot find that there are changes in the api)
Proposed improvement:
Since hammer now supports re-running commands, we can improve user experience in production installations by detecting such situations, trying to fetch new apidoc and running the command again.
- Detect that a resource is missing in the api (see https://github.com/theforeman/hammer-cli/blob/master/lib/hammer_cli/apipie/resource.rb#L55).
- Raise an appropriate exception and force fetch new apidoc (order of this steps can be different based on whether we fetch the docs from an exception handler or from a command).
- Exception handler requests command retry (HammerCLI::EX_RETRY).
- If the resource is still missing, hammer should print help with a message like: "Unfortunately the server does not support such operation. Please make sure that you have correct version of the Foreman and plugins installed." (see https://github.com/theforeman/hammer-cli/blob/master/lib/hammer_cli/apipie/command.rb#L42)
- Commands need to be able to redefine the default message. There are corner cases when an api resource can be missing for different reason (eg. missing organizations when they're disabled). The error message should reflect that.
- Re-try has to be performed only once to prevent infinite loops.
- The "NoMethodError (undefined method `resource' for HammerCLI::MainCommand:Class)" should be fixed together with implementing the retry mechanism.
Updated by Tomáš Strachota over 6 years ago
- Related to Bug #23253: hammer auth-source fails with undefined method `resource' for HammerCLI::MainCommand:Class added
Actions