Merge lp:~ted/ubuntu-app-launch/lp1575990-more-tollerant-stop into lp:ubuntu-app-launch/16.04

Proposed by Ted Gould
Status: Merged
Approved by: Larry Price
Approved revision: 222
Merged at revision: 225
Proposed branch: lp:~ted/ubuntu-app-launch/lp1575990-more-tollerant-stop
Merge into: lp:ubuntu-app-launch/16.04
Diff against target: 186 lines (+88/-38)
5 files modified
tools/ubuntu-app-list-pids.cpp (+17/-7)
tools/ubuntu-app-pid.cpp (+21/-11)
tools/ubuntu-app-stop.cpp (+17/-7)
tools/ubuntu-helper-start.cpp (+15/-5)
tools/ubuntu-helper-stop.cpp (+18/-8)
To merge this branch: bzr merge lp:~ted/ubuntu-app-launch/lp1575990-more-tollerant-stop
Reviewer Review Type Date Requested Status
Larry Price Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+293581@code.launchpad.net

Commit message

Handle exceptions and print errors with command line tools

Description of the change

We don't need apport bugs for people messing up their arguments

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Larry Price (larryprice) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tools/ubuntu-app-list-pids.cpp'
2--- tools/ubuntu-app-list-pids.cpp 2016-02-09 21:12:54 +0000
3+++ tools/ubuntu-app-list-pids.cpp 2016-05-03 02:24:05 +0000
4@@ -29,15 +29,25 @@
5 return 1;
6 }
7
8- auto appid = ubuntu::app_launch::AppID::parse(argv[1]);
9- auto app = ubuntu::app_launch::Application::create(appid, ubuntu::app_launch::Registry::getDefault());
10-
11- for (auto instance : app->instances())
12- {
13- for (auto pid : instance->pids())
14+ auto appid = ubuntu::app_launch::AppID::find(argv[1]);
15+ if (appid.empty()) {
16+ std::cerr << "Unable to find app for appid: " << argv[1] << std::endl;
17+ return 1;
18+ }
19+
20+ try {
21+ auto app = ubuntu::app_launch::Application::create(appid, ubuntu::app_launch::Registry::getDefault());
22+
23+ for (auto instance : app->instances())
24 {
25- std::cout << pid << std::endl;
26+ for (auto pid : instance->pids())
27+ {
28+ std::cout << pid << std::endl;
29+ }
30 }
31+ } catch (std::runtime_error &e) {
32+ std::cerr << "Unable to find application for '" << std::string(appid) << "': " << e.what() << std::endl;
33+ return 1;
34 }
35
36 return 0;
37
38=== modified file 'tools/ubuntu-app-pid.cpp'
39--- tools/ubuntu-app-pid.cpp 2016-02-09 21:12:54 +0000
40+++ tools/ubuntu-app-pid.cpp 2016-05-03 02:24:05 +0000
41@@ -30,15 +30,25 @@
42 return 1;
43 }
44
45- auto appid = ubuntu::app_launch::AppID::parse(argv[1]);
46- auto app = ubuntu::app_launch::Application::create(appid, ubuntu::app_launch::Registry::getDefault());
47- auto pid = app->instances()[0]->primaryPid();
48-
49- if (pid == 0)
50- {
51- return 1;
52- }
53-
54- std::cout << pid << std::endl;
55- return 0;
56+ auto appid = ubuntu::app_launch::AppID::find(argv[1]);
57+ if (appid.empty()) {
58+ std::cerr << "Unable to find app for appid: " << argv[1] << std::endl;
59+ return 1;
60+ }
61+
62+ try {
63+ auto app = ubuntu::app_launch::Application::create(appid, ubuntu::app_launch::Registry::getDefault());
64+ auto pid = app->instances()[0]->primaryPid();
65+
66+ if (pid == 0)
67+ {
68+ return 1;
69+ }
70+
71+ std::cout << pid << std::endl;
72+ return 0;
73+ } catch (std::runtime_error &e) {
74+ std::cerr << "Unable to find application for '" << std::string(appid) << "': " << e.what() << std::endl;
75+ return 1;
76+ }
77 }
78
79=== modified file 'tools/ubuntu-app-stop.cpp'
80--- tools/ubuntu-app-stop.cpp 2016-02-09 21:12:54 +0000
81+++ tools/ubuntu-app-stop.cpp 2016-05-03 02:24:05 +0000
82@@ -1,5 +1,5 @@
83 /*
84- * Copyright 2013 Canonical Ltd.
85+ * Copyright © 2016 Canonical Ltd.
86 *
87 * This program is free software: you can redistribute it and/or modify it
88 * under the terms of the GNU General Public License version 3, as published
89@@ -29,12 +29,22 @@
90 return 1;
91 }
92
93- auto appid = ubuntu::app_launch::AppID::parse(argv[1]);
94- auto app = ubuntu::app_launch::Application::create(appid, ubuntu::app_launch::Registry::getDefault());
95-
96- for (auto instance : app->instances())
97- {
98- instance->stop();
99+ auto appid = ubuntu::app_launch::AppID::find(argv[1]);
100+ if (appid.empty()) {
101+ std::cerr << "Unable to find app for appid: " << argv[1] << std::endl;
102+ return 1;
103+ }
104+
105+ try {
106+ auto app = ubuntu::app_launch::Application::create(appid, ubuntu::app_launch::Registry::getDefault());
107+
108+ for (auto instance : app->instances())
109+ {
110+ instance->stop();
111+ }
112+ } catch (std::runtime_error &e) {
113+ std::cerr << "Unable to find application for '" << std::string(appid) << "': " << e.what() << std::endl;
114+ return 1;
115 }
116
117 return 0;
118
119=== modified file 'tools/ubuntu-helper-start.cpp'
120--- tools/ubuntu-helper-start.cpp 2016-02-09 21:12:54 +0000
121+++ tools/ubuntu-helper-start.cpp 2016-05-03 02:24:05 +0000
122@@ -30,11 +30,21 @@
123 }
124
125 auto type = ubuntu::app_launch::Helper::Type::from_raw(argv[1]);
126- auto appid = ubuntu::app_launch::AppID::parse(argv[2]);
127+ auto appid = ubuntu::app_launch::AppID::find(argv[2]);
128+ if (appid.empty()) {
129+ std::cerr << "Unable to find helper for appid: " << argv[1] << std::endl;
130+ return 1;
131+ }
132
133 auto registry = std::make_shared<ubuntu::app_launch::Registry>();
134- auto helper = ubuntu::app_launch::Helper::create(type, appid, registry);
135-
136- helper->launch();
137- return 0;
138+
139+ try {
140+ auto helper = ubuntu::app_launch::Helper::create(type, appid, registry);
141+
142+ helper->launch();
143+ return 0;
144+ } catch (std::runtime_error &e) {
145+ std::cerr << "Unable to find helper for '" << std::string(appid) << "' type '" << type.value() << "': " << e.what() << std::endl;
146+ return 1;
147+ }
148 }
149
150=== modified file 'tools/ubuntu-helper-stop.cpp'
151--- tools/ubuntu-helper-stop.cpp 2016-02-09 21:12:54 +0000
152+++ tools/ubuntu-helper-stop.cpp 2016-05-03 02:24:05 +0000
153@@ -30,15 +30,25 @@
154 }
155
156 auto type = ubuntu::app_launch::Helper::Type::from_raw(argv[1]);
157- auto appid = ubuntu::app_launch::AppID::parse(argv[2]);
158+ auto appid = ubuntu::app_launch::AppID::find(argv[2]);
159+ if (appid.empty()) {
160+ std::cerr << "Unable to find helper for appid: " << argv[1] << std::endl;
161+ return 1;
162+ }
163
164 auto registry = std::make_shared<ubuntu::app_launch::Registry>();
165- auto helper = ubuntu::app_launch::Helper::create(type, appid, registry);
166-
167- for (auto instance : helper->instances())
168- {
169- instance->stop();
170+
171+ try {
172+ auto helper = ubuntu::app_launch::Helper::create(type, appid, registry);
173+
174+ for (auto instance : helper->instances())
175+ {
176+ instance->stop();
177+ }
178+
179+ return 0;
180+ } catch (std::runtime_error &e) {
181+ std::cerr << "Unable to find helper for '" << std::string(appid) << "' type '" << type.value() << "': " << e.what() << std::endl;
182+ return 1;
183 }
184-
185- return 0;
186 }

Subscribers

People subscribed via source and target branches