From aea9b0054b73090ebe38bdfa55b4cde7fefb0a1d Mon Sep 17 00:00:00 2001 From: Henri DF Date: Tue, 29 Mar 2016 19:31:34 -0700 Subject: [PATCH] Minor error handling improvements --- userspace/digwatch/digwatch.cpp | 2 +- userspace/digwatch/fields.cpp | 2 +- userspace/digwatch/lua/output.lua | 5 +++++ userspace/digwatch/lua/rule_loader.lua | 4 ++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/userspace/digwatch/digwatch.cpp b/userspace/digwatch/digwatch.cpp index 0a010c8a..3ed38aff 100644 --- a/userspace/digwatch/digwatch.cpp +++ b/userspace/digwatch/digwatch.cpp @@ -114,7 +114,7 @@ void do_inspect(sinsp* inspector, if(lua_pcall(ls, 2, 0, 0) != 0) { const char* lerr = lua_tostring(ls, -1); - string err = "Error installing rules: " + string(lerr); + string err = "Error invoking function output: " + string(lerr); throw sinsp_exception(err); } } diff --git a/userspace/digwatch/fields.cpp b/userspace/digwatch/fields.cpp index 3285a8f7..cd3d31ae 100644 --- a/userspace/digwatch/fields.cpp +++ b/userspace/digwatch/fields.cpp @@ -47,7 +47,7 @@ int digwatch_fields::field(lua_State *ls) if(chk == NULL) { - string err = "nonexistent fieldname passed to digwatch.field()" + string(fieldname); + string err = "nonexistent fieldname passed to digwatch.field(): " + string(fieldname); fprintf(stderr, "%s\n", err.c_str()); throw sinsp_exception("digwatch.field() error"); } diff --git a/userspace/digwatch/lua/output.lua b/userspace/digwatch/lua/output.lua index 86448b22..5f1e00eb 100644 --- a/userspace/digwatch/lua/output.lua +++ b/userspace/digwatch/lua/output.lua @@ -24,6 +24,11 @@ function mod.first_sequence(evt, fieldname, key, format) msg = digwatch.format_event(evt, formatter) print (msg) end + if field_value == nil then + formatter = digwatch.formatter(format) + s = digwatch.format_event(evt, formatter) + error("first_sequence: field '"..fieldname.."' is nil in event ("..s..")") + end first_sequence_state[key][field_value] = now end diff --git a/userspace/digwatch/lua/rule_loader.lua b/userspace/digwatch/lua/rule_loader.lua index 21799203..bb5fae9d 100644 --- a/userspace/digwatch/lua/rule_loader.lua +++ b/userspace/digwatch/lua/rule_loader.lua @@ -164,6 +164,10 @@ end evt = nil function on_event(evt_, rule_id) + if state.outputs[rule_id] == nil then + error ("rule_loader.on_event(): event with invalid rule_id: ", rule_id) + end + if state.outputs[rule_id].type == "format" then print(digwatch.format_event(evt_, state.outputs[rule_id].formatter)) elseif state.outputs[rule_id].type == "function" then