diff options
| author | Igor Pashev <pashev.igor@gmail.com> | 2012-04-20 17:32:20 +0400 |
|---|---|---|
| committer | Igor Pashev <pashev.igor@gmail.com> | 2012-04-20 17:32:20 +0400 |
| commit | b72eeb00ec591c646c44cceddd3781a0b6e065e5 (patch) | |
| tree | 01fe6ab62d96d269224635da219f76a03b62ba2e | |
| parent | d27594ad1939ad48a1b25553428662ce5bc8d130 (diff) | |
| download | node-augeas-b72eeb00ec591c646c44cceddd3781a0b6e065e5.tar.gz | |
aug_init() might return non-null handle
| -rw-r--r-- | libaugeas.cc | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/libaugeas.cc b/libaugeas.cc index ed30e66..585a4b8 100644 --- a/libaugeas.cc +++ b/libaugeas.cc @@ -25,6 +25,16 @@ extern "C" { // Yes, that bad using namespace v8; + +inline void throw_aug_error_msg(augeas *aug) +{ + std::string msg = aug_error_message(aug); + msg += ": "; + msg += aug_error_minor_message(aug); + ThrowException(Exception::Error(String::New(msg.c_str()))); +} + + class LibAugeas : public node::ObjectWrap { public: static void Init(Handle<Object> target); @@ -133,9 +143,17 @@ Handle<Value> LibAugeas::New(const Arguments& args) obj->m_aug = aug_init(root.length() ? root.c_str() : NULL, loadpath.length() ? loadpath.c_str() : NULL, flags); + /* + * If flags have AUG_NO_ERR_CLOSE aug_init() might return non-null + * augeas handle which can be used to get error code and message. + */ if (NULL == obj->m_aug) { ThrowException(Exception::Error(String::New("aug_init() failed"))); return scope.Close(Undefined()); + } else if (AUG_NOERROR != aug_error(obj->m_aug)) { + throw_aug_error_msg(obj->m_aug); + aug_close(obj->m_aug); + return scope.Close(Undefined()); } obj->Wrap(args.This()); @@ -143,14 +161,6 @@ Handle<Value> LibAugeas::New(const Arguments& args) return args.This(); } -inline void throw_aug_error_msg(augeas *aug) -{ - std::string msg = aug_error_message(aug); - msg += ": "; - msg += aug_error_minor_message(aug); - ThrowException(Exception::Error(String::New(msg.c_str()))); -} - /* * Wrapper of aug_get() - get exactly one value */ |
