Errors when setting default tracks

This is something I have already discussed on IRC with @facundobatista, just leaving it here so it doesn’t get lost in channel traffic.

It seems the error message for when no tracks exist (other that the default latest) or the track name is typoed produces the same error message:

sergiusens@gotham:~/projects/snapcore/snapcraft$ surl -a staging-package_update https://dashboard.staging.snapcraft.io/dev/api/snaps/3X1pu4K4BTC5WA3wmVoVa2oJZtNAZ7Mn/metadata -d '{"default_track": "foo"}' | jq .
{
  "error_list": [
    {
      "code": "invalid-choice",
      "message": "Select a valid choice. That choice is not one of the available choices.",
      "extra": {
        "value": "foo",
        "field": "default_track"
      }
    }
  ]
}

It would be ideal if we could have two different errors for this, maybe:

  • code: no-tracks
  • code: invalid-track (invalid-choice is fine), an attribute in extra and message could list what the valid tracks are.

I don’t think it makes sense to say there are no tracks, since there’s always default and latest available. I agree that the error could hint at valid tracks, but it can’t list all of them (since the list may be arbitrarily large).

But you can not set the default-track to default or latest, so those are not really “choices”.

We can have two codes, with these messages and extra info:

When the snap doesn’t have created tracks (so, only “latest”, which is by large the most common case):

  • code: no-tracks
  • message: “The snap doesn’t have tracks to be set as default”
  • extra:
    • field: default_track
    • value: foo

When the snap do have tracks but given one is wrong:

  • code: invalid-choice
  • message: “Select a valid choice. That choice is not one of the available choices.”
  • extra:
    • field: default_track
    • value: foo
    • sample_available: [‘track1’, ‘track2’, ‘track3’] # note that this will just show max 10 items

What do you think?