* Support for search API v2.
* Small renames. Avoid extra search.Private && user check in findV1 code (thanks pedronis).
* Check Snap-Store-Version when deciding about search v1 fallback.
* Added unit test for expected search fields with v2.
* Re-organized some unit tests to use apiV1 flag to drive test logic. Add extra checks to ensure v2 api was hit.
* Return an error if scope is anything but "wide" or empty string.
* Added extra test for 404 handling if store is new enough.
* Also request store-url, website and common-ids fields (now supported by the store).
* Update the test to check common ids with v2.
* Handle error-list with search v2. Remove obsolete XXX comments related to common-ids (thanks pedronis).
* Add a comment.
* Always decode the response if status is 200/201
* Remove unneeded copyNonZeroFrom (thanks pedronis).
* Updated the comments.
* Restore two v1 test checks (made them conditional instead of commented out) (thanks pedronis).
* Remove duplicated checks (thanks pedronis).
* Rename 500 tests (once -> Once). Removed unintended change to buy test related to content-type (thanks pedronis).
* Rename search v2 endpoint from /search to /find.
* Rename search v2-related names to find, e.g. searchV2Path -> findPath.
* Clarify and rename 500 tests.
* Bump store version check for find v1 fallback.
* Give the permanent 500 tests more elaborate names.
* Fix spelling.
When a snap action (that is, a POST to the store's refresh endpoint)
results in a single error for a single operation on a single snap, the
current code raises it as an InternalError.
This means a download of an unknown snap becomes an internal error; a
download of a snap from the wrong channel becomes an internal error,
etc. This relatively minor issue becomes user-visible wackiness with
the switch to download being via snapd (and using the mentioned
endpoint).
This change fixes that, such that _if_ it's a single operation on a
single snap returning a single error, then the error raised is the
internal one.
More work could be done to coalesce things such that if it's the same
error for multiple snaps it's handled differently; this would simplify
the "no refreshes found" logging and reporting, I suspect (but haven't
checked).
Before this change, every snap refresh would log, even without DEBUG,
something like:
Jul 17 08:03:16 fleet snapd[4819]: 2018/07/17 08:03:16.096014 storehelpers.go:398: cannot refresh:
Jul 17 08:03:16 fleet snapd[4819]: snap "bofh": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "interdenominational-counterintelligences": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "shellcheck": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "unifonter": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "hello-world": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "wethr": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "cavestory": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "nethack": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "tmnationsforever": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "flare-rpg": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "xbill-xaw": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "quake-shareware": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "telegram-desktop": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "bash-shell-rpg": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "go": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "shattered-pixel-dungeon": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "xonotic": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "youtube-dl-casept": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "mosaic": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "spotify": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "firefox": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "http": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "minecraft": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "vlc": snap has no updates available
Jul 17 08:03:16 fleet snapd[4819]: snap "test-snapd-tools": snap has no updates available
this change turns things around, and instead you'll get
Jul 17 16:02:49 fleet snapd[5123]: 2018/07/19 16:02:49.310941 storehelpers.go:398: cannot refresh: snap has no updates available: "atom", "bash-shell-rpg", "cavestory", "core", "firefox", "flare-rpg", "gnome-3-26-1604", "gnome-calculator", "go", "gtk-common-themes", "hello-world", "http", "interdenominational-counterintelligences", "minecraft", "mosaic", "nethack", "quake-shareware", "shattered-pixel-dungeon", "shellcheck", "spotify", "telegram-desktop", "test-snapd-tools", "tmnationsforever", "unifonter", "vlc", "wethr", "xbill-xaw", "xonotic", "youtube-dl-casept"
which is IMHO better.
It still goes multi-line if there's more than one "kind" of error
(still reversed, “error message: quoted list of snaps”, though).
This uses the new extra "releases" information on store "revision-not-found" errors to produce better errors when a revision is not available for the given channel or architecture.
The extra information when available is passed back over the snapd API using two new error kinds:
* snap-channel-not-available
* snap-architecture-not-available
This allows clients to distinguish bad queries and to do something
useful in their UI. This was requested in bug:
https://bugs.launchpad.net/snapd/+bug/1717573
This also removes the store.ErrEmptyQuery which is never created
in the current code.
This converts the singleton asserts.ErrNotFound to a richer asserts.NotFoundError struct carrying Type and optionally PrimaryKey, similar to store.AssertionNotFoundError which then gets folded with this.
This means code doesn't have to worry anymore which is which or to convert between the two. And when possible there is more information around. Though Backstores can continue to return minimal information (Type but not Headers in the new error).
A helper asserts.IsNotFound is also added to cover the simple old ==/!= asserts.ErrNotFound needs.
This also fixes/adjust some error handling to usually not repeat the richer information twice.
There's still *so* much to do in this area. Still, in this branch:
* added an error kind "snap-local" for when the store returns
ErrLocalSnap
* added an error kind "snap-not-found", for 404s
* dropped the store.NoUpdateAvailableError type in favour of
store.ErrNoUpdateAvailable; the snap name contained in the error
type could be wrong or misleading, and the client alreayd knows the
name of the snap.
* moved cmd/snap's clientErrorToCmdMessage to errorToCmdMessage, and
put the type checking in the function itself, to avoid repeating it
for every caller. Still some more work to be done there before I'm
happy with that.
* made cmd/snap's errorToCmdMessage take a *client.SnapOptions, which
it can then use to better explain SnapNotFound.
* lastly, errorToCmdMessage handles snap-local.
This splits LookupRefresh out of store's ListRefresh, and makes
snapstate's Update use the new one. The difference is that
LookupRefresh can tell the difference between "this snap does not
exist [in the channel you asked about]" and "there are no updates for
this snap"; ListRefresh confounds the two situations, leading to some
hilarity.
Also includes some incidental refactoring of ListRefresh in order to
avoid DRY.
The neat thing about this one is probably that the new (private) store
method refreshForCandidate, called by both LookupRefresh and
ListRefresh to actually contact the store, has been made mockable. The
tests for LookupRefresh are done using this, and I'll be rewriting the
ListRefresh ones to do similarly once I'm happy with the coverage for
the helper funcs (which this branch also adds).
This splits LookupRefrsh out of store's ListRefresh, and makes
snapstate's Update use the new one. The difference is that
LookupRefresh can tell the difference between "this snap does not
exist [in the channel you asked about]" and "there are no updates for
this snap"; ListRefresh confounds the two situations, leading to some
hilarity.
Also includes some incidental refactoring of ListRefresh in order to
avoid DRY.
- The new store API takes the price as a string, so convert the float price.
- We avoid taking a string for the price on the snapd API, as the price is still a float in the store index API, and the existing properties on snaps from /v2/find, etc.
- Also handle one of the expected HTTP codes, 402, which appears to mean payment failed for unspecified reason.
- Refactor store.Buy tests into a table.
- Fix copy paste error.
- Remove the word "valid" from errors.
- Make storeErrors implement the Go error interface.
- Simply return the whole &errors list from ReadyToBuy.
- Compose the ReadyToBuy tests into a single test, with tabular input.