Skip to content

improve error message of oras attach when subject artifact is not specified #1424

Closed

Description

@qweeah

When using oras attach, if a user forgot to provide the subject artifact reference and only specifies one to-be-uploaded file, ORAS CLI will output (tested in bash, different shell might have different output):

> ARTIFACT=
> oras attach --artifact-type test/example $ARTIFACT./test.json
Error: neither file nor annotation provided in the command
Usage: oras attach [flags] --artifact-type=<type> <name>{:<tag>|@<digest>} <file>[:<layer_media_type>] [...]
To attach to an existing artifact, please provide files via argument or annotations via flag "--annotation". Run "oras attach -h" for more options and examplesdigest]

Input was parsed under a wrong consumption: user does specify subject artifact reference ./layers, which actually is a file reference to be attached. This error can be avoided by parsing the only input argument. If the reference is valid, continue with current output. If it's not, give corresponding hint like:

Error: "./test.json" is an invalid artifact reference
Did you forget to specify a subject artifact?

Activity

  1. added
    ux
    on Jun 21, 2024
  2. added this to the v1.3.0 milestone on Jun 21, 2024
  3. qweeah commented on Jun 21, 2024

    @qweeah
    ContributorAuthor

    This should also resolve part of #1404

  4. FeynmanZhou commented on Jun 21, 2024

    @FeynmanZhou
    Member

    Can you pls also add the wrong oras attach command in this issue?

  5. qweeah commented on Jun 24, 2024

    @qweeah
    ContributorAuthor

    Sample error output (phrasing and wording still TBD)

    > ./bin/linux/amd64/oras attach --artifact-type test/example "a-------" 
    Error: "a-------": invalid reference: missing registry or repository
    Have you specified an artifact reference to attach to? Please make sure the provided reference is in the form of <registry>/<repo>[:tag|@digest][:tag|@digest]

    Depends on different behavior of shell, if an empty env variable is interpolated into "" (zsh)

    > ARTIFACT=
    > ./bin/linux/amd64/oras attach --artifact-type test/example $ARTIFACT my.json
    Error: "my.json": invalid reference: missing registry or repository
    Have you specified an artifact reference to attach to? Please make sure the provided reference is in the form of <registry>/<repo>[:tag|@digest]
    > ./bin/linux/amd64/oras attach localhost:5000/test my.json --artifact-type test/example
    Error: "localhost:5000/test": no tag or digest specified
    Usage: oras attach [flags] --artifact-type=<type> <name>{:<tag>|@<digest>} <file>[:<layer_media_type>] [...]
    Please specify a reference in the form of "<name>:<tag>" or "<name>@<digest>". Run "oras attach -h" for more options and examples

    If an empty env variable is omitted (bash)

    > ARTIFACT=
    > ./bin/linux/amd64/oras attach --artifact-type test/example $ARTIFACT ./my.json
    Error: "./my.json": no tag or digest specified
    Usage: oras attach [flags] --artifact-type=<type> <name>{:<tag>|@<digest>} <file>[:<layer_media_type>] [...]
    Have you specified an artifact reference to attach to? Please specify a reference in the form of "<name>:<tag>" or "<name>@<digest>". Run "oras attach -h" for more options and examples
  6. FeynmanZhou commented on Jun 27, 2024

    @FeynmanZhou
    Member

    @qweeah For this case, how about improving the error message as follows:

    > oras attach --artifact-type test/example $ARTIFACT ./layers 
    Error: "./layers" is an invalid artifact reference.
    Usage: oras attach [flags] --artifact-type=<type> <name>{:<tag>|@<digest>} <file>[:<layer_media_type>] | --annotation "key=val"
    To attach files to an object, please specify a valid artifact reference and files via arguments in sequence". Run "oras attach -h" for more options and examples.
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ux

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions