summaryrefslogtreecommitdiff
path: root/COMMON_ERRORS.md
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2021-02-05 01:05:58 +0300
committerEd Tanous <ed@tanous.net>2021-02-06 10:01:05 +0300
commita88e75fc5972bec57c5255b54fa332dc543eb81a (patch)
tree3cb711a2957e1a1c6537fb0ee11ffa888bbf6ecb /COMMON_ERRORS.md
parent74849bef22033fc8ff0011e1c48721ff973bd2a2 (diff)
downloadbmcweb-a88e75fc5972bec57c5255b54fa332dc543eb81a.tar.xz
Number the common errors
In code review, despite them being documented, people still tend to make these mistakes. Having them numbered allows responding with comments that are much simpler for a maintainer, with quick comments like: "Common error #2" While this might not seem like a huge savings, for maintainers having to review 10s of reviews per day, having an optimized workflow helps a lot with time savings and little improvements add up over time. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I877cbbf50c1e20448f31464f820114073bba513e
Diffstat (limited to 'COMMON_ERRORS.md')
-rw-r--r--COMMON_ERRORS.md20
1 files changed, 10 insertions, 10 deletions
diff --git a/COMMON_ERRORS.md b/COMMON_ERRORS.md
index 0157165bbe..16c7908aa7 100644
--- a/COMMON_ERRORS.md
+++ b/COMMON_ERRORS.md
@@ -9,7 +9,7 @@ not-always-obvious ways, or impose a pattern that tends to cause hard to find
bugs, or bugs that appear later. Every one has been submitted to code review
multiple times.
-### Directly dereferencing a pointer without checking for validity first
+### 1. Directly dereferencing a pointer without checking for validity first
```C++
int myBadMethod(const nlohmann::json& j){
const int* myPtr = j.get_if<int>();
@@ -18,7 +18,7 @@ int myBadMethod(const nlohmann::json& j){
```
This pointer is not guaranteed to be filled, and could be a null dereference.
-### String views aren't null terminated
+### 2. String views aren't null terminated
```C++
int getIntFromString(const std::string_view s){
return std::atoi(s.data());
@@ -28,7 +28,7 @@ This will give the right answer much of the time, but has the possibility to
fail when string\_view is not null terminated. Use from\_chars instead, which
takes both a pointer and a length
-### Not handling input errors
+### 3. Not handling input errors
```C++
int getIntFromString(const std::string& s){
return std::atoi(s.c_str());
@@ -39,7 +39,7 @@ undefined behavior at system level. Code needs to check for validity of the
string, ideally with something like from\_chars, and return the appropriate error
code.
-### Walking off the end of a string
+### 4. Walking off the end of a string
```C++
std::string getFilenameFromPath(const std::string& path){
size_t index = path.find("/");
@@ -51,7 +51,7 @@ std::string getFilenameFromPath(const std::string& path){
}
```
-### Using methods that throw (or not handling bad inputs)
+### 5. Using methods that throw (or not handling bad inputs)
```C++
int myBadMethod(nlohmann::json& j){
return j.get<int>();
@@ -98,7 +98,7 @@ asio methods, and prefer the one that returns an error code instead of throwing.
- boost::asio::ip::tcp::acceptor::listen();
- boost::asio::ip::address::make\_address();
-### Blocking functions
+### 6. Blocking functions
bmcweb uses a single reactor for all operations. Blocking that reactor for any
amount of time causes all other operations to stop. The common blocking
@@ -120,7 +120,7 @@ system, the fact that most filesystem accesses are into tmpfs (and therefore
should be "fast" most of the time) and in general how little the filesystem is
used in practice.
-### Lack of locking between subsequent calls
+### 7. Lack of locking between subsequent calls
While global data structures are discouraged, they are sometimes required to
store temporary state for operations that require it. Given the single
threaded nature of bmcweb, they are not required to be explicitly threadsafe,
@@ -140,7 +140,7 @@ void secondCallbackInFlow(){
In the above case, the first callback needs a check to ensure that
currentOperation is not already being used.
-### Wildcard reference captures in lambdas
+### 8. Wildcard reference captures in lambdas
```
std::string x; auto mylambda = [&](){
x = "foo";
@@ -156,7 +156,7 @@ captured by value or by reference. The above prototypes would change to
[&x]()... Which makes clear that x is captured, and its lifetime needs tracked.
-### URLs should end in "/"
+### 9. URLs should end in "/"
```C++
BMCWEB("/foo/bar");
```
@@ -168,7 +168,7 @@ used by users. While many specifications do not require this, it resolves a
whole class of bug that we've seen in the past.
-### URLs constructed in aggregate
+### 10. URLs constructed in aggregate
```C++
std::string routeStart = "/redfish/v1";