Snap try messaging and user experience

Hi there,

A few things raised my attention when running snap try:

$ sudo snap try prime
error: The publisher of snap "prime" has indicated that they do not consider this revision to be of
       production quality and that it is only meant for development or testing at this point. As a
       consequence this snap will not refresh automatically and may perform arbitrary system
       changes outside of the security sandbox snaps are generally confined to, which may put your
       system at risk.

       If you understand and want to proceed repeat the command including --devmode; if instead you
       want to install the snap forcing it into strict confinement repeat the command including
       --jailmode.

And here they are:

  • My snap is not called prime
  • Considering this is a developer centric command, why would I need to specify --devmode (or classic). Can this at least be transformed into a yes/no prompt for the try situation?
2 Likes

Thanks for this report.

To fix the error from the directory name we need something like the following diff. Its a bit silly that it uses the dirname.

diff --git a/cmd/snap/error.go b/cmd/snap/error.go
index 5174ad6a01..caa11a4550 100644
--- a/cmd/snap/error.go
+++ b/cmd/snap/error.go
@@ -168,9 +168,11 @@ Try 'snapcraft prime' in your project directory, then 'snap try' again.`)
 			}
 		}
 	case client.ErrorKindSnapAlreadyInstalled:
+		snapName = err.Value.(string)
 		isError = false
 		msg = i18n.G(`snap %q is already installed, see 'snap help refresh'`)
 	case client.ErrorKindSnapNeedsDevMode:
+		snapName = err.Value.(string)
 		if opts != nil && opts.Dangerous {
 			msg = i18n.G("snap %q requires devmode or confinement override")
 			break
@@ -186,6 +188,7 @@ If you understand and want to proceed repeat the command including --devmode;
 if instead you want to install the snap forcing it into strict confinement
 repeat the command including --jailmode.`)
 	case client.ErrorKindSnapNeedsClassic:
+		snapName = err.Value.(string)
 		msg = i18n.G(`
 This revision of snap %q was published using classic confinement and thus may
 perform arbitrary system changes outside of the security sandbox that snaps are
@@ -194,6 +197,7 @@ usually confined to, which may put your system at risk.
 If you understand and want to proceed repeat the command including --classic.
 `)
 	case client.ErrorKindSnapNotClassic:
+		snapName = err.Value.(string)
 		msg = i18n.G(`snap %q is not compatible with --classic`)
 	case client.ErrorKindLoginRequired:
 		usesSnapName = false

For the second part - try behaves very much like install so I’m not sure we want to automatically fallback to devmode. It may give the wrong impression, i.e. “when I did snap try it worked but snap install it didn’t”. My impression is that the message is clear what needs to be done but we can discuss this more.

Hey, about this second part. The reason I ask for these is because we are working on a feature (snapcraft try) which is supposed to expose prime which lives inside a multipass/lxd VM/container instance and run snap try on the exposed prime directory. If there is no interactivenes I cannot think of a nice option which does’t require us to implement all the toggles you already have into snapcraft try and will resort to just saying something like "you can now run snap try <exposed-prime>.

That latter part we will probably do in any case until, if agreed to, some interactiveness is added to snap try.