From cf50ebad50ef1c8321f0dde23afd28a51489b3c7 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Wed, 27 Mar 2013 21:48:02 +0100 Subject: Make simple commands check stderr Don't assume all operations will complete successfully, check the error output to see if something happened. --- clark.js | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/clark.js b/clark.js index 70cbc53..b1ea691 100644 --- a/clark.js +++ b/clark.js @@ -58,7 +58,7 @@ function clark_add_url(I, url, title) + tags.split(',').map(function (str) { return str.trim(); }).join("' '") + "'"; - yield shell_command(command); + yield clark_shell_command(command); } function clark_add(I) { @@ -186,8 +186,12 @@ function clark_edit(I) { if (description != "") command += "--description '" + description + "' "; - var result = yield shell_command(command); - I.window.minibuffer.message("CLark done"); + var result = yield clark_shell_command(command); + + if (result) + I.window.minibuffer.message("CLark done"); + else + I.window.minibuffer.message("Error during CLark operation."); } } interactive("clark-edit", "Edit information for the current URL.", @@ -228,8 +232,12 @@ function clark_remove(I) { let url_string = load_spec_uri_string(load_spec(I.buffer.top_frame)); let command = clark_program + ' remove "' + url_string + '"'; - let result = yield shell_command(command); - I.window.minibuffer.message("CLark done"); + let result = yield clark_shell_command(command); + + if (result) + I.window.minibuffer.message("CLark done"); + else + I.window.minibuffer.message("Error during CLark operation."); } interactive("clark-remove", "Remove the bookmark of the current URL" + " from the database.", clark_remove); @@ -246,12 +254,33 @@ function clark_set_tags(I) { + tags.split(',').map( function (str) { return "'" + str.trim() + "'"; } ).join(" "); - let result = yield shell_command(command); - I.window.minibuffer.message("CLark done"); + let result = yield clark_shell_command(command); + + if (result) + I.window.minibuffer.message("CLark done"); + else + I.window.minibuffer.message("Error during CLark operation."); } interactive("clark-set-tags", "Replace the tags for the bookmark of" + " the current URL.", clark_set_tags); +function clark_shell_command(command) +{ + let data = "", error = ""; + yield shell_command( + command, + $fds = [{ output: async_binary_string_writer("") }, + { input: async_binary_reader( + function (s) data += s || "" + )}, + { input: async_binary_reader( + function (s) error += s || "" + )}] + ); + + yield co_return(error == ""); +} + define_keymap("clark_keymap"); define_key(clark_keymap, "?", "clark-exists-p"); -- cgit v1.2.3-54-g00ecf