Merge ~yoshikadokawa/layer-snap:lp1938271 into layer-snap:master

Proposed by Yoshi Kadokawa
Status: Merged
Approved by: Tom Haddon
Approved revision: 52b05b8bb6b7371ceca9be7081697b14f6f231ca
Merged at revision: d935a04074740e14feb0b73d485952b2546ae04c
Proposed branch: ~yoshikadokawa/layer-snap:lp1938271
Merge into: layer-snap:master
Diff against target: 21 lines (+9/-1)
1 file modified
lib/charms/layer/snap.py (+9/-1)
Reviewer Review Type Date Requested Status
Tom Haddon Approve
James Troup (community) Approve
Canonical IS Reviewers Pending
Review via email: mp+406295@code.launchpad.net

Commit message

Fix unexpected error when getting snap channel

LP: #1938271

Description of the change

Added extra try-exception layer to avoid unexpected errors.

To post a comment you must log in.
Revision history for this message
Yoshi Kadokawa (yoshikadokawa) wrote :

It's been a week now, but would someone be able to review this?

Revision history for this message
James Troup (elmo) wrote :

LGTM

review: Approve
Revision history for this message
Tom Haddon (mthaddon) wrote :

One small comment inline, otherwise looks good.

Revision history for this message
Tom Haddon (mthaddon) wrote :

LGTM

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision d935a04074740e14feb0b73d485952b2546ae04c

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/charms/layer/snap.py b/lib/charms/layer/snap.py
2index 6909748..06cc4b1 100644
3--- a/lib/charms/layer/snap.py
4+++ b/lib/charms/layer/snap.py
5@@ -300,7 +300,15 @@ def get_installed_channel(snapname):
6 hookenv.WARNING,
7 )
8 return
9- return subprocess.check_output(cmd).decode("utf-8", errors="replace").partition("tracking:")[-1].split()[0]
10+ try:
11+ return subprocess.check_output(cmd).decode("utf-8", errors="replace").partition("tracking:")[-1].split()[0]
12+ except Exception as e:
13+ # If it fails to get the channel information(ex. installed via resource), return nothing.
14+ hookenv.log(
15+ "Cannot get snap tracking (channel): {}".format(e),
16+ hookenv.WARNING,
17+ )
18+ return
19
20
21 def _snap_args(

Subscribers

People subscribed via source and target branches