Warnings are currently available from snapd in the edge channel.
While performing its background duties, snapd is occasionally presented with a fact or an event that the user should be made aware of. If this fact or event isn’t serious enough to stop normal operation, snapd will generate a warning instead.
Examples of possible warning triggers include a snap service suddenly stopping, system resources running low, or perhaps the discovery that the confinement features of the local system put a user’s data or privacy at risk.
Warnings are presented to the user via the snapd client, typically either the snap command line tool or a desktop application such as GNOME Software.
A warning is designed to be useful and not easily ignored. As such, there will only ever be one warning with a given message in the system.
Each warning carries two timestamps and two timeout values: the timestamps store the date and time of the first and last occurrences of an event, while the timeouts store when the warning expires and the frequency of how often the user needs to be reminded if the event keeps occurring.
Warnings are continually presented to the user until the user manually acknowledges them, at which point they are silenced for a given period of time. If the triggering event doesn’t reoccur, the warning won’t be shown to the user again. If the event does reoccur, the new warning will be displayed after the frequency timeout.
Warnings from the snap
tool
When using snap on the command line, any warnings the user has not yet acknowledged can be listed with snap warnings
:
$ snap warnings
Last occurrence Warning
8 days ago, at 13:41 BST hello world number one
8 days ago, at 13:44 BST hello world number two
After running snap warnings
, the user can acknowledge the warnings with snap okay
. The warnings will no longer appear:
$ snap okay
$ snap warnings
No further warnings.
To see all warnings not-yet expired, regardless of whether they’ve been acknowledged, use snap warnings --all
:
$ snap warnings --all
Last occurrence Warning
8 days ago, at 13:41 BST hello world number one
8 days ago, at 13:44 BST hello world number two
Unacknowledged warnings will appear after every successful user-facing command:
$ snap list hello-world
Name Version Rev Tracking Publisher Notes
hello-world 6.3 27 stable canonical✓ -
WARNING: There are 2 new warnings. See 'snap warnings'.
To clear this warning footer in the output, view the warnings with snap warnings
:
$ snap warnings
Last occurrence Warning
8 days ago, at 13:41 BST hello world number one
8 days ago, at 13:44 BST hello world number two
$ snap list hello-world
Name Version Rev Tracking Publisher Notes
hello-world 6.3 27 stable canonical✓ -
API notes
Every sync
response will carry two new top level entries: warning-count
and warning-timestamp
. The client is expected to store the timestamp of the last time the user saw the warnings listing and compare it to warning-timestamp
, alerting the user immediately if the timestamp in the response is newer than the stored one. The snap
client does this in the warnings.json
file in the user config directory.
/v2/warnings
GET
: returns a list of all unacknowledged warnings. With select=all
, returns all known warnings. An expired warning is unknown. Warnings have:
-
"message"
, the message to be shown to the user; -
"first-added"
, when the message was first encountered; -
"last-added"
, when it was last encountered; -
"last-shown"
, when it was last acknowledged by the user; -
"expire-after"
, how long after"last-added"
it will be forgotten; -
"repeat-after"
, how long after"last-shown"
it will be presented to the user again.
POST
: with "action"
set to "okay"
and "timestamp"
set to the stored client timestamp, acknowledges all warnings that would have been returned by /v2/warnings
at that time.