osquery-1/osquery/core/status.cpp
Alexander 5ef576a99c
Create a success and failure static factory for Status (#4627)
Consider this PR as a cosmetic one.

Creating Status class object in the code is not so clear. It is not so obvious that defatult costructed Status is success. Also it is not obvious that status with zero code is success and non-zero is failure.

To fix it I created 2 static methods to make construction of some particular status clear to reader.

* Use assert to check code in Status::failure in debut mode

* Rename success_code constant to kSuccessCode
according to style guide
2018-06-26 17:36:26 +01:00

29 lines
779 B
C++

/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under both the Apache 2.0 license (found in the
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
* in the COPYING file in the root directory of this source tree).
* You may select, at your option, one of the above-listed licenses.
*/
#include <osquery/logger.h>
#include <osquery/status.h>
#include <cassert>
#include <iostream>
namespace osquery {
constexpr int Status::kSuccessCode;
Status Status::failure(int code, std::string message) {
assert(code != Status::kSuccessCode &&
"Using 'failure' to create Status object with a kSuccessCode");
return Status(code, std::move(message));
}
} // namespace osquery