Skip to content

Better error handling and documentation around query_packwerk console #3

Description

@technicalpickles

I noticed this while trying a few variations of the command to get help usage:

❯ query_packwerk console --help
Loading packwerk context in --help...
/Users/josh.nichols/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/query_packwerk-0.1.0/lib/query_packwerk/console.rb:16:in 'Dir.chdir': No such file or directory @ dir_chdir0 - --help (Errno::ENOENT)
        from /Users/josh.nichols/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/query_packwerk-0.1.0/lib/query_packwerk/console.rb:16:in 'QueryPackwerk::Console.start'
        from /Users/josh.nichols/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11987/lib/types/private/methods/call_validation.rb:282:in 'UnboundMethod#bind_call'
        from /Users/josh.nichols/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11987/lib/types/private/methods/call_validation.rb:282:in 'T::Private::Methods::CallValidation.validate_call'
        from /Users/josh.nichols/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11987/lib/types/private/methods/_methods.rb:277:in 'block in QueryPackwerk::Console._on_method_added'
        from /Users/josh.nichols/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/query_packwerk-0.1.0/lib/query_packwerk/cli.rb:16:in 'QueryPackwerk::CLI#console'
        from /Users/josh.nichols/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11987/lib/types/private/methods/call_validation.rb:282:in 'UnboundMethod#bind_call'
        from /Users/josh.nichols/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11987/lib/types/private/methods/call_validation.rb:282:in 'T::Private::Methods::CallValidation.validate_call'
        from /Users/josh.nichols/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/sorbet-runtime-0.5.11987/lib/types/private/methods/_methods.rb:277:in 'block in QueryPackwerk::CLI#_on_method_added'
        from /Users/josh.nichols/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/command.rb:28:in 'Thor::Command#run'
        from /Users/josh.nichols/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/invocation.rb:127:in 'Thor::Invocation#invoke_command'
        from /Users/josh.nichols/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor.rb:538:in 'Thor.dispatch'
        from /Users/josh.nichols/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/thor-1.3.2/lib/thor/base.rb:584:in 'Thor::Base::ClassMethods#start'
        from /Users/josh.nichols/.local/share/mise/installs/ruby/3.4.2/lib/ruby/gems/3.4.0/gems/query_packwerk-0.1.0/exe/query_packwerk:7:in '<top (required)>'
        from /Users/josh.nichols/.local/share/mise/installs/ruby/3.4.2/bin/query_packwerk:25:in 'Kernel#load'
        from /Users/josh.nichols/.local/share/mise/installs/ruby/3.4.2/bin/query_packwerk:25:in '<main>'

sig { params(directory: String).void }
def console(directory = Dir.pwd)

❯ query_packwerk help console
Usage:
  query_packwerk console

Query packwerk in the current directory via console

I think this could benefit from a few improvements:

  • make sure --help is supported everywhere with a class_option
  • update desc call to include DIRECTORY, ie desc 'console DIRECTORY'
  • make sure the description matches the behavior (ie don't say 'current directory' if it can be passed in)
  • error check that directory exists, and give an appropriate error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions