Is the exit code 0 of `snapctl get SOME_NONEXISTENT_OPTION` stable?


Presently (snap 2.51.3), probing for a non-existent configuration option produces:

  1. an empty string
  2. an exit code of 0 (success)
# snapctl get xxxxxxxxx; echo $?


It seems that as long as there is an appropriate snap context and snapd is running, the command is considered a success, even if the option itself does not exist.

I would like to rely on this behavior, but doesn’t mention exit codes for the get command.

More worrying is that snap get name option produces an error rather than an empty string, along with an exit code of 1.

Any clarification here would be great, thank you.


I’m still looking for clarification here. Would this be better suited for the snapd issue tracker?

Thank you.

I don’t think we can commit to the exit codes for snapctl being something that can be maintained/relied upon, if you are trying to check if a key was set is to use the -d option and parse the JSON, if the key is not set, it will be absent from the JSON:

$ snapctl get -d "foo"
	"foo": "bar"
$ snapctl get -d "a"
1 Like