[grilo-plugins] lua-factory: include error message for broken source



commit 8f669020c2365e3d428753a0f5bb2c90fed39e20
Author: Victor Toso <me victortoso com>
Date:   Thu May 19 21:44:06 2016 +0200

    lua-factory: include error message for broken source
    
    When grl_lua_operations_get_current_op() fails issues a lua_error
    which points to file and line number where the error happened.
    
    If we can't retrieve the current operation it means that
    grl.callback() was called and the grilo operation has been finalized.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=764078

 src/lua-factory/grl-lua-library-operations.c |    4 +-
 src/lua-factory/grl-lua-library.c            |   38 +++++++++++++++++++++++---
 2 files changed, 36 insertions(+), 6 deletions(-)
---
diff --git a/src/lua-factory/grl-lua-library-operations.c b/src/lua-factory/grl-lua-library-operations.c
index 7bad46d..68ec319 100644
--- a/src/lua-factory/grl-lua-library-operations.c
+++ b/src/lua-factory/grl-lua-library-operations.c
@@ -667,8 +667,8 @@ grl_lua_operations_get_current_op (lua_State *L)
     /* Source State is finalized. At this state it should be waiting the
      * watchdog to free its data. Only a broken source would request
      * OperationSpec on FINALIZED State */
-    GRL_WARNING ("operation-id: %u is on FINALIZED state and cannot be changed",
-                 os->operation_id);
+    GRL_DEBUG ("The grilo operation ended when grl.callback() was called. "
+               "No current operation for op-id: %u", os->operation_id);
     return NULL;
   }
   return os;
diff --git a/src/lua-factory/grl-lua-library.c b/src/lua-factory/grl-lua-library.c
index 6b3ef14..b101653 100644
--- a/src/lua-factory/grl-lua-library.c
+++ b/src/lua-factory/grl-lua-library.c
@@ -746,7 +746,13 @@ grl_l_operation_get_options (lua_State *L)
   luaL_argcheck (L, lua_isstring (L, 1), 1, "expecting option (string)");
 
   os = grl_lua_operations_get_current_op (L);
-  g_return_val_if_fail (os != NULL, 0);
+  if (os == NULL) {
+    luaL_error (L, "grl.get_options() failed: Can't retrieve current operation. "
+                   "Source is broken as grl.callback() has been called but source "
+                   "is still active");
+    return 0;
+  }
+
   option = lua_tostring (L, 1);
 
   if (g_strcmp0 (option, "type") == 0) {
@@ -905,7 +911,12 @@ grl_l_operation_get_keys (lua_State *L)
   GList *it;
 
   os = grl_lua_operations_get_current_op (L);
-  g_return_val_if_fail (os != NULL, 0);
+  if (os == NULL) {
+    luaL_error (L, "grl.get_requested_keys() failed: Can't retrieve current operation. "
+                   "Source is broken as grl.callback() has been called but source "
+                   "is still active");
+    return 0;
+  }
 
   registry = grl_registry_get_default ();
   lua_newtable (L);
@@ -1033,6 +1044,12 @@ grl_l_media_get_keys (lua_State *L)
   GrlMedia *media;
 
   os = grl_lua_operations_get_current_op (L);
+  if (os == NULL) {
+    luaL_error (L, "grl.get_media_keys() failed: Can't retrieve current operation. "
+                   "Source is broken as grl.callback() has been called but source "
+                   "is still active");
+    return 0;
+  }
   media = os->media;
 
   if (media == NULL) {
@@ -1120,6 +1137,12 @@ grl_l_fetch (lua_State *L)
                  "expecting callback function after network parameters");
 
   os = grl_lua_operations_get_current_op (L);
+  if (os == NULL) {
+    luaL_error (L, "grl.fetch() failed: Can't retrieve current operation. "
+                   "Source is broken as grl.callback() has been called but source "
+                   "is still active");
+    return 0;
+  }
 
   /* keep arguments aligned */
   if (lua_isfunction (L, 2)) {
@@ -1219,8 +1242,9 @@ grl_l_callback (lua_State *L)
   nparam = lua_gettop (L);
   os = grl_lua_operations_get_current_op (L);
   if (os == NULL) {
-    luaL_error (L, "Source is broken as callback was called "
-                "after the operation has been finalized");
+    luaL_error (L, "grl.callback() failed: Can't retrieve current operation. "
+                   "Source is broken as grl.callback() has been called but source "
+                   "is still active");
     return 0;
   }
 
@@ -1448,6 +1472,12 @@ grl_l_unzip (lua_State *L)
 
   wc = net_wc_new_with_options (L, 3);
   os = grl_lua_operations_get_current_op (L);
+  if (os == NULL) {
+    luaL_error (L, "grl.unzip() failed: Can't retrieve current operation. "
+                   "Source is broken as grl.callback() has been called but source "
+                   "is still active");
+    return 0;
+  }
 
   uo = g_new0 (UnzipOperation, 1);
   uo->L = L;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]