Merge lp:~robru/libfriends/exceptions into lp:libfriends
- exceptions
- Merge into trunk
Proposed by
Robert Bruce Park
Status: | Merged |
---|---|
Approved by: | Ken VanDine |
Approved revision: | 54 |
Merged at revision: | 45 |
Proposed branch: | lp:~robru/libfriends/exceptions |
Merge into: | lp:libfriends |
Diff against target: |
854 lines (+216/-171) 6 files modified
examples/example-vala.vala (+48/-11) gtk/account.vala (+18/-4) gtk/entry.vala (+58/-23) src/service.vala (+69/-121) src/utils.vala (+0/-1) tests/vala/test-service.vala (+23/-11) |
To merge this branch: | bzr merge lp:~robru/libfriends/exceptions |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ken VanDine | Approve | ||
Review via email: mp+143167@code.launchpad.net |
Commit message
Make libfriends throw exceptions, so we can catch and test for them in the testsuite.
Description of the change
Ok Ken, I massaged this to get rid of as many compiler warnings as I could.
To post a comment you must log in.
Revision history for this message
Ken VanDine (ken-vandine) wrote : | # |
lp:~robru/libfriends/exceptions
updated
- 54. By Robert Bruce Park
-
Add descriptions for @throws documentation.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'examples/example-vala.vala' |
2 | --- examples/example-vala.vala 2013-01-09 19:30:53 +0000 |
3 | +++ examples/example-vala.vala 2013-01-14 19:51:21 +0000 |
4 | @@ -29,7 +29,12 @@ |
5 | |
6 | public Example (MainLoop loop) |
7 | { |
8 | - service = new Friends.Service(); |
9 | + try { |
10 | + service = new Friends.Service(); |
11 | + } catch (GLib.IOError e) { |
12 | + warning (e.message); |
13 | + service = null; |
14 | + } |
15 | } |
16 | |
17 | public void run_example (string[] args) |
18 | @@ -41,7 +46,11 @@ |
19 | switch (args[1]) { |
20 | case "--refresh": |
21 | stdout.printf("Refreshing friends\n"); |
22 | - service.refresh(); |
23 | + try { |
24 | + service.refresh(); |
25 | + } catch (GLib.IOError e) { |
26 | + warning (e.message); |
27 | + } |
28 | return; |
29 | case "--features": |
30 | if (args.length < 3) { |
31 | @@ -49,13 +58,21 @@ |
32 | return; |
33 | } |
34 | stdout.printf("Getting features for %s\n", args[2]); |
35 | - var features = service.features(args[2]); |
36 | - foreach(string feature in features) |
37 | - stdout.printf("%s\n", feature); |
38 | + try { |
39 | + var features = service.features(args[2]); |
40 | + foreach(string feature in features) |
41 | + stdout.printf("%s\n", feature); |
42 | + } catch (GLib.IOError e) { |
43 | + warning (e.message); |
44 | + } |
45 | return; |
46 | case "--shutdown": |
47 | stdout.printf("Shutting down the friends service\n"); |
48 | - service.quit(); |
49 | + try { |
50 | + service.quit(); |
51 | + } catch (GLib.IOError e) { |
52 | + warning (e.message); |
53 | + } |
54 | return; |
55 | |
56 | case "--like": |
57 | @@ -69,7 +86,11 @@ |
58 | uint acct = int.parse(args[i+1]); |
59 | string id = args[i+2]; |
60 | stdout.printf("Liked...\n"); |
61 | - service.like(acct, id); |
62 | + try { |
63 | + service.like(acct, id); |
64 | + } catch (GLib.IOError e) { |
65 | + warning (e.message); |
66 | + } |
67 | } else { |
68 | PrintUsage (); |
69 | } |
70 | @@ -82,7 +103,11 @@ |
71 | uint acct = int.parse(args[i+1]); |
72 | string id = args[i+2]; |
73 | stdout.printf("Unliked...\n"); |
74 | - service.unlike(acct, id); |
75 | + try { |
76 | + service.unlike(acct, id); |
77 | + } catch (GLib.IOError e) { |
78 | + warning (e.message); |
79 | + } |
80 | } else { |
81 | PrintUsage (); |
82 | } |
83 | @@ -95,7 +120,11 @@ |
84 | uint acct = int.parse(args[i+1]); |
85 | string id = args[i+2]; |
86 | stdout.printf("Retweet...\n"); |
87 | - service.retweet(acct, id); |
88 | + try { |
89 | + service.retweet(acct, id); |
90 | + } catch (GLib.IOError e) { |
91 | + warning (e.message); |
92 | + } |
93 | } else { |
94 | PrintUsage (); |
95 | } |
96 | @@ -132,7 +161,11 @@ |
97 | string message = args[i+2]; |
98 | stdout.printf("Posting...\n"); |
99 | stdout.printf ("message: %s\n account: %u\n", message, acct); |
100 | - service.send_message(acct, message); |
101 | + try { |
102 | + service.send_message(acct, message); |
103 | + } catch (GLib.IOError e) { |
104 | + warning (e.message); |
105 | + } |
106 | } else { |
107 | PrintUsage (); |
108 | } |
109 | @@ -151,7 +184,11 @@ |
110 | string message_id = args[i+2]; |
111 | string message = args[i+3]; |
112 | stdout.printf("Replying...\n"); |
113 | - service.send_reply(acct, message_id, message); |
114 | + try { |
115 | + service.send_reply(acct, message_id, message); |
116 | + } catch (GLib.IOError e) { |
117 | + warning (e.message); |
118 | + } |
119 | } else { |
120 | PrintUsage (); |
121 | } |
122 | |
123 | === modified file 'gtk/account.vala' |
124 | --- gtk/account.vala 2013-01-11 17:25:44 +0000 |
125 | +++ gtk/account.vala 2013-01-14 19:51:21 +0000 |
126 | @@ -82,8 +82,15 @@ |
127 | } |
128 | set { |
129 | GLib.Value t = value; |
130 | - _account.set_value("friends/color", t); |
131 | - _account.store_blocking(); |
132 | + try |
133 | + { |
134 | + _account.set_value("friends/color", t); |
135 | + _account.store_blocking(); |
136 | + } |
137 | + catch (Ag.AccountsError e) |
138 | + { |
139 | + warning (e.message); |
140 | + } |
141 | } |
142 | } |
143 | |
144 | @@ -117,8 +124,15 @@ |
145 | GLib.Value t = false; |
146 | if (value == "1") |
147 | t = true; |
148 | - _account.set_value("friends/send_enabled", t); |
149 | - _account.store_blocking(); |
150 | + try |
151 | + { |
152 | + _account.set_value("friends/send_enabled", t); |
153 | + _account.store_blocking(); |
154 | + } |
155 | + catch (Ag.AccountsError e) |
156 | + { |
157 | + warning (e.message); |
158 | + } |
159 | } |
160 | } |
161 | |
162 | |
163 | === modified file 'gtk/entry.vala' |
164 | --- gtk/entry.vala 2013-01-11 17:25:44 +0000 |
165 | +++ gtk/entry.vala 2013-01-14 19:51:21 +0000 |
166 | @@ -48,7 +48,12 @@ |
167 | construct |
168 | { |
169 | set_orientation (Gtk.Orientation.VERTICAL); |
170 | - service = new Friends.Service (); |
171 | + try { |
172 | + service = new Friends.Service (); |
173 | + } catch (GLib.IOError e) { |
174 | + warning (e.message); |
175 | + return; |
176 | + } |
177 | |
178 | text_view = new InputTextView (service); |
179 | target_bar = new AccountTargetBar (); |
180 | @@ -97,7 +102,12 @@ |
181 | |
182 | construct |
183 | { |
184 | - service = new Friends.Service (); |
185 | + try { |
186 | + service = new Friends.Service (); |
187 | + } catch (GLib.IOError e) { |
188 | + warning (e.message); |
189 | + return; |
190 | + } |
191 | |
192 | text_view = new InputTextView (service); |
193 | send_bar = new SendBar (); |
194 | @@ -124,14 +134,14 @@ |
195 | private Friends.Service service; |
196 | |
197 | /** |
198 | - * The {@link Gdk.Color} for the foreground |
199 | + * The {@link Gdk.RGBA} for the foreground |
200 | */ |
201 | - public Gdk.Color fg_color; |
202 | + public Gdk.RGBA fg_color; |
203 | |
204 | /** |
205 | - * The {@link Gdk.Color} for the error state |
206 | + * The {@link Gdk.RGBA} for the error state |
207 | */ |
208 | - public Gdk.Color error_color; |
209 | + public Gdk.RGBA error_color; |
210 | |
211 | bool last_was_shortened = false; |
212 | private string _mid = null; |
213 | @@ -152,16 +162,25 @@ |
214 | |
215 | construct |
216 | { |
217 | - service = new Friends.Service (); |
218 | + try { |
219 | + service = new Friends.Service (); |
220 | + } catch (GLib.IOError e) { |
221 | + warning (e.message); |
222 | + return; |
223 | + } |
224 | |
225 | unowned Gtk.BindingSet binding_set; |
226 | binding_set = Gtk.BindingSet.by_class (typeof (InputTextView).class_ref ()); |
227 | Gtk.BindingEntry.add_signal (binding_set, Gdk.keyval_from_name ("Return"), 0, "submit", 0); |
228 | Gtk.BindingEntry.add_signal (binding_set, Gdk.keyval_from_name ("KP_Enter"), 0, "submit", 0); |
229 | Gtk.BindingEntry.add_signal (binding_set, Gdk.keyval_from_name ("Escape"), 0, "clear", 0); |
230 | - fg_color = get_style ().text[Gtk.StateType.NORMAL]; |
231 | - |
232 | - Gdk.Color.parse ("indianred", out error_color); |
233 | + |
234 | + // FIXME: How do we tell this StyleContext to get the color from the right place? |
235 | + Gtk.StyleContext context = new Gtk.StyleContext (); |
236 | + fg_color = context.get_color (Gtk.StateFlags.NORMAL); |
237 | + |
238 | + error_color = Gdk.RGBA (); |
239 | + error_color.parse("indianred"); |
240 | |
241 | get_buffer ().changed.connect (on_text_changed); |
242 | get_buffer ().insert_text.connect (on_text_inserted); |
243 | @@ -232,8 +251,12 @@ |
244 | service.send_message(msg, null, null, null); |
245 | } |
246 | */ |
247 | - service.send_message(null, msg); |
248 | - debug ("(submit) Message: %s posted", msg); |
249 | + try { |
250 | + service.send_message(null, msg); |
251 | + debug ("(submit) Message: %s posted", msg); |
252 | + } catch (GLib.IOError e) { |
253 | + warning (e.message); |
254 | + } |
255 | reset(); |
256 | } |
257 | |
258 | @@ -245,8 +268,10 @@ |
259 | private void on_text_changed () |
260 | { |
261 | var chars = get_buffer ().get_char_count (); |
262 | - modify_fg (Gtk.StateType.NORMAL, |
263 | - chars > MAX_MESSAGE_LENGTH ? error_color : fg_color); |
264 | + override_color ( |
265 | + Gtk.StateFlags.NORMAL, |
266 | + chars > MAX_MESSAGE_LENGTH ? error_color : fg_color |
267 | + ); |
268 | } |
269 | |
270 | private void on_text_inserted (ref Gtk.TextIter iter, string text, int len) |
271 | @@ -258,9 +283,14 @@ |
272 | { |
273 | var buf = get_buffer (); |
274 | Signal.stop_emission_by_name (buf, "insert-text") ; |
275 | - var shrt = service.shorten (text); |
276 | - last_was_shortened = true; |
277 | - buf.insert (ref iter, shrt, -1); |
278 | + try { |
279 | + var shrt = service.shorten (text); |
280 | + last_was_shortened = true; |
281 | + buf.insert (ref iter, shrt, -1); |
282 | + } catch (GLib.IOError e) { |
283 | + warning (e.message); |
284 | + return; |
285 | + } |
286 | } |
287 | else |
288 | { |
289 | @@ -300,9 +330,9 @@ |
290 | { |
291 | context.translate(-1, -1); |
292 | factor = 1.0; |
293 | - } else if (get_state () == 2) { |
294 | + } else if (get_state_flags () == Gtk.StateFlags.PRELIGHT) { |
295 | factor = 0.3; |
296 | - } else if (get_state () == 1) { |
297 | + } else if (get_state_flags () == Gtk.StateFlags.ACTIVE) { |
298 | factor = 0.5; |
299 | } |
300 | |
301 | @@ -354,10 +384,10 @@ |
302 | { |
303 | Object (spacing:0); |
304 | } |
305 | - |
306 | + |
307 | /* |
308 | * The {@Ag.Account.id} of the account button to be displayed |
309 | - * This is used in the case of replies or private messages |
310 | + * This is used in the case of replies or private messages |
311 | * where the post will only go to a single account |
312 | */ |
313 | public uint? selected { |
314 | @@ -402,7 +432,12 @@ |
315 | if (GLib.FileUtils.test (local_icon_path, GLib.FileTest.IS_DIR)) |
316 | icon_theme.prepend_search_path (local_icon_path); |
317 | |
318 | - service = new Friends.Service(); |
319 | + try { |
320 | + service = new Friends.Service (); |
321 | + } catch (GLib.IOError e) { |
322 | + warning (e.message); |
323 | + return; |
324 | + } |
325 | accounts_service = new FriendsAccounts(); |
326 | |
327 | // Add buttons to button area at the bottom |
328 | @@ -490,7 +525,7 @@ |
329 | return account_button; |
330 | } |
331 | |
332 | - /* |
333 | + /* |
334 | * Set the number of remaining characters allowed to post |
335 | * @param chars Number of characters remaining |
336 | */ |
337 | |
338 | === modified file 'src/service.vala' |
339 | --- src/service.vala 2013-01-11 18:53:44 +0000 |
340 | +++ src/service.vala 2013-01-14 19:51:21 +0000 |
341 | @@ -51,8 +51,10 @@ |
342 | /** |
343 | * Establish a connection to the local Friends Service daemon. |
344 | * @return a new Service |
345 | + * @throws GLib.IOError if failed to connect to the |
346 | + * Friends Service daemon. |
347 | */ |
348 | - public Service () |
349 | + public Service () throws IOError |
350 | { |
351 | Object (); |
352 | try |
353 | @@ -65,7 +67,8 @@ |
354 | } |
355 | catch (GLib.IOError e) |
356 | { |
357 | - warning ("Unable to get Gwibber service: "+e.message); |
358 | + warning ("Unable to get Friends service: "+e.message); |
359 | + throw (e); |
360 | } |
361 | } |
362 | |
363 | @@ -82,16 +85,17 @@ |
364 | * parameter and is rather arbitrary. |
365 | * |
366 | * @since 0.1 |
367 | + * @throws GLib.IOError if action failed. |
368 | */ |
369 | - private bool do(string action, string account_id, string argument) |
370 | + private bool do(string action, string account_id, string argument) throws IOError |
371 | { |
372 | try { |
373 | service.Do(action, account_id, argument); |
374 | return true; |
375 | - } catch (GLib.Error e) { |
376 | + } catch (GLib.IOError e) { |
377 | warning (e.message); |
378 | + throw (e); |
379 | } |
380 | - return false; |
381 | } |
382 | |
383 | /** |
384 | @@ -101,28 +105,22 @@ |
385 | * to exit, preventing any other clients from accessing it. |
386 | * |
387 | * @since 0.1 |
388 | + * @throws GLib.IOError if the call to Friends.Service.Quit fails. |
389 | */ |
390 | - public void quit() |
391 | + public void quit() throws IOError |
392 | { |
393 | - try { |
394 | - service.Quit(); |
395 | - } catch (GLib.IOError e) { |
396 | - warning (e.message); |
397 | - } |
398 | + service.Quit(); |
399 | } |
400 | |
401 | /** |
402 | * Perform a refresh of all enabled accounts. |
403 | * |
404 | * @since 0.1 |
405 | + * @throws GLib.IOError if the call to Friends.Service.Refresh fails. |
406 | */ |
407 | - public void refresh() |
408 | + public void refresh() throws IOError |
409 | { |
410 | - try { |
411 | - service.Refresh(); |
412 | - } catch (GLib.IOError e) { |
413 | - warning (e.message); |
414 | - } |
415 | + service.Refresh(); |
416 | } |
417 | |
418 | /** |
419 | @@ -137,8 +135,9 @@ |
420 | * uploaded photo. |
421 | * |
422 | * @since 0.1 |
423 | + * @throws GLib.IOError if the call to Friends.Service.Upload fails. |
424 | */ |
425 | - public void upload(uint account_id, string uri, string description) |
426 | + public void upload(uint account_id, string uri, string description) throws IOError |
427 | { |
428 | string result_url = null; |
429 | service.Upload.begin(account_id.to_string(), uri, description, (obj, res) => { |
430 | @@ -146,6 +145,7 @@ |
431 | service.Upload.end(res, out result_url); |
432 | } catch (IOError e) { |
433 | warning (e.message); |
434 | + throw (e); |
435 | } |
436 | }); |
437 | } |
438 | @@ -161,16 +161,11 @@ |
439 | * uploaded file. |
440 | * |
441 | * @since 0.1 |
442 | - * @throws GLib.IOError if uploading the image failed. |
443 | + * @throws GLib.IOError if the call to Friends.Service.Upload fails. |
444 | */ |
445 | public async void upload_async(uint account_id, string uri, string description, out string result_url) throws IOError |
446 | { |
447 | - try { |
448 | - yield service.Upload(account_id.to_string(), uri, description, out result_url); |
449 | - } catch (IOError e) { |
450 | - warning (e.message); |
451 | - throw (e); |
452 | - } |
453 | + yield service.Upload(account_id.to_string(), uri, description, out result_url); |
454 | } |
455 | |
456 | |
457 | @@ -189,16 +184,17 @@ |
458 | * @return ``true`` for success, ``false`` otherwise |
459 | * |
460 | * @since 0.1 |
461 | + * @throws GLib.IOError if the call to Friends.Service.SendReply fails. |
462 | */ |
463 | - public bool send_reply(uint account_id, string message_id, string message) |
464 | + public bool send_reply(uint account_id, string message_id, string message) throws IOError |
465 | { |
466 | try { |
467 | service.SendReply(message, account_id.to_string(), message_id); |
468 | return true; |
469 | - } catch (GLib.Error e) { |
470 | + } catch (GLib.IOError e) { |
471 | warning (e.message); |
472 | + throw (e); |
473 | } |
474 | - return false; |
475 | } |
476 | |
477 | |
478 | @@ -210,19 +206,15 @@ |
479 | * @return ``true`` for success, ``false`` otherwise |
480 | * |
481 | * @since 0.1 |
482 | + * @throws GLib.IOError if the call to Friends.Service.SendMessage fails. |
483 | */ |
484 | - public bool send_message(uint? account_id, string message) |
485 | + public bool send_message(uint? account_id, string message) throws IOError |
486 | { |
487 | - try { |
488 | - if (account_id != null) |
489 | - return do("send", account_id.to_string(), message); |
490 | - else |
491 | - service.SendMessage(message); |
492 | - return true; |
493 | - } catch (GLib.Error e) { |
494 | - warning (e.message); |
495 | - } |
496 | - return false; |
497 | + if (account_id != null) |
498 | + return do("send", account_id.to_string(), message); |
499 | + else |
500 | + service.SendMessage(message); |
501 | + return true; |
502 | } |
503 | |
504 | /** |
505 | @@ -233,15 +225,11 @@ |
506 | * @return ``true`` for success, ``false`` otherwise |
507 | * |
508 | * @since 0.1 |
509 | + * @throws GLib.IOError if the call to Friends.Service.Do fails. |
510 | */ |
511 | - public bool retweet(uint account_id, string message_id) |
512 | + public bool retweet(uint account_id, string message_id) throws IOError |
513 | { |
514 | - try { |
515 | - return do("retweet", account_id.to_string(), message_id); |
516 | - } catch (GLib.Error e) { |
517 | - warning (e.message); |
518 | - } |
519 | - return false; |
520 | + return do("retweet", account_id.to_string(), message_id); |
521 | } |
522 | |
523 | /** |
524 | @@ -254,15 +242,11 @@ |
525 | * @return ``true`` for success, ``false`` otherwise |
526 | * |
527 | * @since 0.1 |
528 | + * @throws GLib.IOError if the call to Friends.Service.Do fails. |
529 | */ |
530 | - public bool home(uint account_id) |
531 | + public bool home(uint account_id) throws IOError |
532 | { |
533 | - try { |
534 | - return do("home", account_id.to_string(), ""); |
535 | - } catch (GLib.Error e) { |
536 | - warning (e.message); |
537 | - } |
538 | - return false; |
539 | + return do("home", account_id.to_string(), ""); |
540 | } |
541 | |
542 | /** |
543 | @@ -276,15 +260,11 @@ |
544 | * @return ``true`` for success, ``false`` otherwise |
545 | * |
546 | * @since 0.1 |
547 | + * @throws GLib.IOError if the call to Friends.Service.Do fails. |
548 | */ |
549 | - public bool wall(uint account_id) |
550 | + public bool wall(uint account_id) throws IOError |
551 | { |
552 | - try { |
553 | - return do("wall", account_id.to_string(), ""); |
554 | - } catch (GLib.Error e) { |
555 | - warning (e.message); |
556 | - } |
557 | - return false; |
558 | + return do("wall", account_id.to_string(), ""); |
559 | } |
560 | |
561 | /** |
562 | @@ -296,18 +276,14 @@ |
563 | * @return ``true`` for success, ``false`` otherwise |
564 | * |
565 | * @since 0.1 |
566 | + * @throws GLib.IOError if the call to Friends.Service.Do fails. |
567 | */ |
568 | - public bool search(uint? account_id, string query) |
569 | + public bool search(uint? account_id, string query) throws IOError |
570 | { |
571 | - try { |
572 | - if (account_id != null) |
573 | - return do("search", account_id.to_string(), query); |
574 | - else |
575 | - return do("search", "", query); |
576 | - } catch (GLib.Error e) { |
577 | - warning (e.message); |
578 | - } |
579 | - return false; |
580 | + if (account_id != null) |
581 | + return do("search", account_id.to_string(), query); |
582 | + else |
583 | + return do("search", "", query); |
584 | } |
585 | |
586 | /** |
587 | @@ -319,15 +295,11 @@ |
588 | * @return ``true`` for success, ``false`` otherwise |
589 | * |
590 | * @since 0.1 |
591 | + * @throws GLib.IOError if the call to Friends.Service.Do fails. |
592 | */ |
593 | - public bool like(uint account_id, string message_id) |
594 | + public bool like(uint account_id, string message_id) throws IOError |
595 | { |
596 | - try { |
597 | - return do("like", account_id.to_string(), message_id); |
598 | - } catch (GLib.Error e) { |
599 | - warning (e.message); |
600 | - } |
601 | - return false; |
602 | + return do("like", account_id.to_string(), message_id); |
603 | } |
604 | |
605 | /** |
606 | @@ -339,15 +311,11 @@ |
607 | * @return ``true`` for success, ``false`` otherwise |
608 | * |
609 | * @since 0.1 |
610 | + * @throws GLib.IOError if the call to Friends.Service.Do fails. |
611 | */ |
612 | - public bool unlike(uint account_id, string message_id) |
613 | + public bool unlike(uint account_id, string message_id) throws IOError |
614 | { |
615 | - try { |
616 | - return do("unlike", account_id.to_string(), message_id); |
617 | - } catch (GLib.Error e) { |
618 | - warning (e.message); |
619 | - } |
620 | - return false; |
621 | + return do("unlike", account_id.to_string(), message_id); |
622 | } |
623 | |
624 | /** |
625 | @@ -359,15 +327,11 @@ |
626 | * @return ``true`` for success, ``false`` otherwise |
627 | * |
628 | * @since 0.1 |
629 | + * @throws GLib.IOError if the call to Friends.Service.Do fails. |
630 | */ |
631 | - public bool delete(uint account_id, string message_id) |
632 | + public bool delete(uint account_id, string message_id) throws IOError |
633 | { |
634 | - try { |
635 | - return do("delete", account_id.to_string(), message_id); |
636 | - } catch (GLib.Error e) { |
637 | - warning (e.message); |
638 | - } |
639 | - return false; |
640 | + return do("delete", account_id.to_string(), message_id); |
641 | } |
642 | |
643 | /** |
644 | @@ -378,15 +342,11 @@ |
645 | * @return ``true`` for success, ``false`` otherwise |
646 | * |
647 | * @since 0.1 |
648 | + * @throws GLib.IOError if the call to Friends.Service.Do fails. |
649 | */ |
650 | - public bool contacts(uint account_id) |
651 | + public bool contacts(uint account_id) throws IOError |
652 | { |
653 | - try { |
654 | - return do("contacts", account_id.to_string(), ""); |
655 | - } catch (GLib.Error e) { |
656 | - warning (e.message); |
657 | - } |
658 | - return false; |
659 | + return do("contacts", account_id.to_string(), ""); |
660 | } |
661 | |
662 | /** |
663 | @@ -396,25 +356,18 @@ |
664 | * @return The shortened URL. |
665 | * |
666 | * @since 0.1 |
667 | + * @throws GLib.IOError if the call to Friends.Service.URLShorten fails. |
668 | */ |
669 | - public string shorten(string url) |
670 | + public string shorten(string url) throws IOError |
671 | { |
672 | - try |
673 | - { |
674 | - return service.URLShorten(url); |
675 | - } |
676 | - catch (GLib.IOError e) |
677 | - { |
678 | - warning (e.message); |
679 | - return url; |
680 | - } |
681 | + return service.URLShorten(url); |
682 | } |
683 | |
684 | /** |
685 | * This method returns a list of all the possible actions |
686 | * supported by a given protocol. This can be used to |
687 | - * determine what actions are available for the requested |
688 | - * protocol. |
689 | + * determine what actions are available for the requested |
690 | + * protocol. |
691 | * |
692 | * @param protocol One of ``facebook``, ``flickr``, |
693 | * ``foursquare``, ``identica``, or ``twitter``. |
694 | @@ -422,19 +375,16 @@ |
695 | * features) if there are no features found for ``protocol``. |
696 | * |
697 | * @since 0.1 |
698 | + * @throws GLib.Error if the call to Friends.Service.GetFeatures fails. |
699 | */ |
700 | - public string[] features(string protocol) |
701 | + public string[] features(string protocol) throws Error |
702 | { |
703 | string[] _features = null; |
704 | - try { |
705 | var parser = new Json.Parser(); |
706 | parser.load_from_data(service.GetFeatures(protocol), -1); |
707 | var nodes = parser.get_root().get_array().get_elements(); |
708 | foreach(var node in nodes) |
709 | _features += node.dup_string (); |
710 | - } catch(GLib.Error e) { |
711 | - warning(e.message); |
712 | - } |
713 | return _features; |
714 | } |
715 | |
716 | @@ -442,14 +392,12 @@ |
717 | * Clear all notifications from the messaging menu. |
718 | * |
719 | * @since 0.1 |
720 | + * @throws GLib.IOError if the call to Friends.Service.ClearIndicators |
721 | + * fails. |
722 | */ |
723 | - public void messaging_menu_clear() |
724 | + public void messaging_menu_clear() throws IOError |
725 | { |
726 | - try { |
727 | - service.ClearIndicators(); |
728 | - } catch (GLib.IOError e) { |
729 | - warning (e.message); |
730 | - } |
731 | + service.ClearIndicators(); |
732 | } |
733 | |
734 | private void connection_offline() |
735 | |
736 | === modified file 'src/utils.vala' |
737 | --- src/utils.vala 2013-01-09 18:50:08 +0000 |
738 | +++ src/utils.vala 2013-01-14 19:51:21 +0000 |
739 | @@ -54,7 +54,6 @@ |
740 | { |
741 | string _avatar_cache_image = Path.build_path (Path.DIR_SEPARATOR_S, Environment.get_user_cache_dir(), "friends/avatars", GLib.Checksum.compute_for_string (GLib.ChecksumType.SHA1, url)); |
742 | debug ("AVATAR PATH: %s", _avatar_cache_image); |
743 | - var file = File.new_for_path (_avatar_cache_image); |
744 | return _avatar_cache_image; |
745 | } |
746 | } |
747 | |
748 | === modified file 'tests/vala/test-service.vala' |
749 | --- tests/vala/test-service.vala 2013-01-09 19:41:41 +0000 |
750 | +++ tests/vala/test-service.vala 2013-01-14 19:51:21 +0000 |
751 | @@ -61,9 +61,20 @@ |
752 | ServiceSuite.test_url_shorten); |
753 | } |
754 | |
755 | + static Friends.Service? get_service () |
756 | + { |
757 | + Friends.Service service = null; |
758 | + try { |
759 | + service = new Friends.Service (); |
760 | + } catch (GLib.IOError e) { |
761 | + warning(e.message); |
762 | + } |
763 | + return service; |
764 | + } |
765 | + |
766 | internal static void test_refresh () |
767 | { |
768 | - var service = new Friends.Service (); |
769 | + var service = get_service (); |
770 | bool success = false; |
771 | try |
772 | { |
773 | @@ -80,7 +91,7 @@ |
774 | |
775 | internal static void test_quit () |
776 | { |
777 | - var service = new Friends.Service (); |
778 | + var service = get_service (); |
779 | bool success = false; |
780 | try |
781 | { |
782 | @@ -97,22 +108,23 @@ |
783 | |
784 | internal static void test_features () |
785 | { |
786 | - var service = new Friends.Service (); |
787 | - string[] features; |
788 | + var service = get_service (); |
789 | + string[] features = null; |
790 | try |
791 | { |
792 | features = service.features ("twitter"); |
793 | } |
794 | - catch (GLib.IOError e) |
795 | + catch (GLib.Error e) |
796 | { |
797 | warning ("Failed to get features - %s", e.message); |
798 | } |
799 | + assert (features != null); |
800 | assert ("send" in features); |
801 | } |
802 | |
803 | internal static void test_upload () |
804 | { |
805 | - var service = new Friends.Service (); |
806 | + var service = get_service (); |
807 | uint acct = 1; |
808 | string uri = "file:///tmp/foo.png"; |
809 | string desc = "Something interesting to say"; |
810 | @@ -129,7 +141,7 @@ |
811 | |
812 | internal static void test_send_message () |
813 | { |
814 | - var service = new Friends.Service (); |
815 | + var service = get_service (); |
816 | uint? acct = null; |
817 | string msg = "A message"; |
818 | bool success = false; |
819 | @@ -147,7 +159,7 @@ |
820 | |
821 | internal static void test_send_message_with_account () |
822 | { |
823 | - var service = new Friends.Service (); |
824 | + var service = get_service (); |
825 | uint acct = 1; |
826 | string msg = "A message"; |
827 | bool success = false; |
828 | @@ -165,7 +177,7 @@ |
829 | |
830 | internal static void test_send_reply () |
831 | { |
832 | - var service = new Friends.Service (); |
833 | + var service = get_service (); |
834 | uint acct = 1; |
835 | string msg = "A message"; |
836 | string msg_id = "100"; |
837 | @@ -184,7 +196,7 @@ |
838 | |
839 | internal static void test_clear_indicators () |
840 | { |
841 | - var service = new Friends.Service (); |
842 | + var service = get_service (); |
843 | bool success = false; |
844 | try |
845 | { |
846 | @@ -200,7 +212,7 @@ |
847 | |
848 | internal static void test_url_shorten () |
849 | { |
850 | - var service = new Friends.Service (); |
851 | + var service = get_service (); |
852 | string result = ""; |
853 | try |
854 | { |
My previous branch was missing descriptions in the docstrings for all the throws I added. I've fixed that in lp:~ken-vandine/friends/exceptions
Please merge that into your branch.