jbang icon indicating copy to clipboard operation
jbang copied to clipboard

"Script or alias could not be found or read" should not be issued if "jbang alias list" lists it

Open koppor opened this issue 2 years ago • 3 comments

Describe the bug

"Script or alias could not be found or read" is output even if the script is shown at jbang alias list

To Reproduce

Steps to reproduce the behavior:

  1. jbang catalog add https://raw.githubusercontent.com/nbbrd/jbang-catalog/master/jbang-catalog.json
  2. > jbang --verbose alias list
    Picked up JAVA_TOOL_OPTIONS: -Duser.language=en
    [jbang] [0:240] jbang version 0.110.1
    [jbang] [0:255] Reading catalog from C:\Users\koppor\.jbang\jbang-catalog.json
    [jbang] [0:286] Reading catalog from classpath:/jbang-catalog.json
    [jbang] [0:299] Using cached file C:\Users\koppor\.jbang\cache\urls\32d7e3573295d223682ea94b393cf5ad399c3fbc872fe793866bbb25cb937610\jbang-catalog.json for remote https://raw.githubusercontent.com/nbbrd/jbang-catalog/master/jbang-catalog.json
    [jbang] [0:300] Reading catalog from https://raw.githubusercontent.com/nbbrd/jbang-catalog/master/jbang-catalog.json
    [jbang] [0:302] Obtained catalog from https://raw.githubusercontent.com/nbbrd/jbang-catalog/master/jbang-catalog.json
    hello-nbbrd = Sandbox - Bill of Materials
               (https://raw.githubusercontent.com/nbbrd/jbang-catalog/master/hello_nbbrd.java)
    heylogs = Keep-a-changelog tool - Bill of Materials
            (https://raw.githubusercontent.com/nbbrd/jbang-catalog/master/heylogs.java)
    sdmx-dl = Download SDMX data - CLI
            (https://raw.githubusercontent.com/nbbrd/jbang-catalog/master/sdmx_dl.java)
    
  3. > jbang --verbose heylogs
    Picked up JAVA_TOOL_OPTIONS: -Duser.language=en
    [jbang] [0:238] jbang version 0.110.1
    [jbang] [0:254] Resolving resource ref: heylogs
    [jbang] [0:261] Reading catalog from C:\Users\koppor\.jbang\jbang-catalog.json
    [jbang] [0:289] Reading catalog from classpath:/jbang-catalog.json
    [jbang] [0:291] Retry using cache-evict: heylogs
    [jbang] [0:294] [ERROR] Script or alias could not be found or read: 'heylogs'
    dev.jbang.cli.ExitException: Script or alias could not be found or read: 'heylogs'
          at dev.jbang.source.ProjectBuilder.resolveChecked(ProjectBuilder.java:244)
          at dev.jbang.source.ProjectBuilder.build(ProjectBuilder.java:218)
          at dev.jbang.cli.Run.doCall(Run.java:73)
          at dev.jbang.cli.BaseCommand.call(BaseCommand.java:145)
          at dev.jbang.cli.BaseCommand.call(BaseCommand.java:21)
          at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
          at picocli.CommandLine.access$1300(CommandLine.java:145)
          at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
          at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
          at dev.jbang.cli.JBang$3.handle(JBang.java:148)
          at dev.jbang.cli.JBang$3.handle(JBang.java:143)
          at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
          at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
          at picocli.CommandLine.execute(CommandLine.java:2078)
          at dev.jbang.Main.main(Main.java:14)
    [jbang] [0:299] If you believe this a bug in jbang, open an issue at https://github.com/jbangdev/jbang/issues
    

Expected behavior

heylogs executed

Alternatively, a hint which command to execute to make the alias really available.

JBang version

> jbang version --verbose
Picked up JAVA_TOOL_OPTIONS: -Duser.language=en
[jbang] [0:238] jbang version 0.110.1
Cache: C:\Users\koppor\.jbang\cache
Config: C:\Users\koppor\.jbang
Repository:C:\Users\koppor\.m2\repository
0.110.1

koppor avatar Sep 08 '23 13:09 koppor

When executing

jbang heylogs@jbang-catalog

everything works.

Do I as user really need to add @jbang-catalog?

koppor avatar Sep 08 '23 22:09 koppor

No, if alias list it without catalog you should be able to run it.

@quintesse rings a bell?

maxandersen avatar Sep 09 '23 08:09 maxandersen

There is indeed something wrong. First of all the fact that jbang choses the very generic name "jbang-catalog". Second I noticed that if you run two jbang catalog add ...../jbang-catalog.json commands with different base URLs the second will just silently overwrite the first.

And finally we should perhaps define once and for all what happens when you add a catalog.

Because if you run jbang properties@maxandersen it's basically the same as running:

jbang catalog add --name maxandersen https://github.com/maxandersen/jbang-catalog/jbang-catalog.json
jbang run properties@maxandersen

So my intuition would be that if you run those two commands manually you should get the same result. Which right now isn't the case. In the second case the aliases will appear without the @maxandersen but you still have to add it to the alias to make things work. So that's obviously a bug.

So to me to fix that bug, the aliases should always appear with @catalogname regardless of how the catalog was added.

But I also know that we wanted to be able to have aliases available directly without the @ in certain cases. But I think we failed to adequately define in what cases and how. (I have some ideas but I don't want to make this post overly long).

quintesse avatar Sep 09 '23 15:09 quintesse