aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2012-04-28 15:14:04 +0400
committerIgor Pashev <pashev.igor@gmail.com>2012-04-28 15:14:04 +0400
commit0b9546e169690ed9ccc32fe9e13181ee7718f046 (patch)
tree37ea984ce86d9b3afe9501df481cf7708f4c127c
parentfe70f6d8b4bf8a7b44a61a83933b6ce481b934b3 (diff)
downloadnode-augeas-0b9546e169690ed9ccc32fe9e13181ee7718f046.tar.gz
Added errorMsg() returning fully qualified error message
-rw-r--r--libaugeas.cc35
1 files changed, 30 insertions, 5 deletions
diff --git a/libaugeas.cc b/libaugeas.cc
index a9570ec..42017b4 100644
--- a/libaugeas.cc
+++ b/libaugeas.cc
@@ -24,20 +24,25 @@ extern "C" { // Yes, that bad
using namespace v8;
-inline void throw_aug_error_msg(augeas *aug)
+inline std::string aug_error_msg(augeas *aug)
{
std::string msg = aug_error_message(aug);
const char *minor = aug_error_minor_message(aug);
const char *details = aug_error_details(aug);
if (NULL != minor) {
- msg += ": ";
+ msg += " - ";
msg += minor;
}
if (NULL != details) {
- msg += " -> ";
+ msg += ": ";
msg += details;
}
- ThrowException(Exception::Error(String::New(msg.c_str())));
+ return msg;
+}
+
+inline void throw_aug_error_msg(augeas *aug)
+{
+ ThrowException(Exception::Error(String::New(aug_error_msg(aug).c_str())));
}
@@ -99,6 +104,7 @@ protected:
static Handle<Value> load (const Arguments& args);
static Handle<Value> insert (const Arguments& args);
static Handle<Value> error (const Arguments& args);
+ static Handle<Value> errorMsg (const Arguments& args);
};
Persistent<FunctionTemplate> LibAugeas::augeasTemplate;
@@ -150,6 +156,7 @@ void LibAugeas::Init(Handle<Object> target)
_NEW_METHOD(load);
_NEW_METHOD(insert);
_NEW_METHOD(error);
+ _NEW_METHOD(errorMsg);
constructor = Persistent<Function>::New(augeasTemplate->GetFunction());
@@ -453,7 +460,7 @@ Handle<Value> LibAugeas::insert(const Arguments& args)
/*
* Wrapper of aug_error()
- * Return the error code from the last API call
+ * Returns the error code from the last API call
*/
Handle<Value> LibAugeas::error(const Arguments& args)
{
@@ -470,6 +477,24 @@ Handle<Value> LibAugeas::error(const Arguments& args)
return scope.Close(Int32::New(rc));
}
+/*
+ * Returns the error message from the last API call,
+ * including all details.
+ */
+Handle<Value> LibAugeas::errorMsg(const Arguments& args)
+{
+ HandleScope scope;
+
+ if (args.Length() != 0) {
+ ThrowException(Exception::TypeError(String::New("Function does not accept arguments")));
+ return scope.Close(Undefined());
+ }
+
+ LibAugeas *obj = ObjectWrap::Unwrap<LibAugeas>(args.This());
+
+ return scope.Close(String::New(aug_error_msg(obj->m_aug).c_str()));
+}
+
struct SaveUV {