envoyproxy / envoyproxy/nighthawk

Safe conversion to absl::StatusCode

Open
#476 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
414
Forks
95
Avg merge
2d 9h
Merged PRs (30d)
11

Description

Casting an integer to an enum outside the defined range doesn't throw but produces undefined behavior. And C++ has no maintainable way to check for the largest value in this enum -- absl::StatusCode has a sentinel value that they say not to use, and it won't work anyway because of the gap from 16 to 20 [0].

Everyone who uses this field is expected to use standard Google codes, maybe through constants like grpc::DATA_LOSS.

One possibility is to warn about the enum conversion in the proto comment.

A safer but stranger alternative would be to define this field as not supporting anything above kAuthenticated=16, not necessarily tracking new absl::StatusCode values as they are added.

[0] https://github.com/abseil/abseil-cpp/blob/fbf0fdab62ac6fcc72b935d505f6837e0884fdc3/absl/status/status.h#L159

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.