pw_status: Use new functions instead of variables
Run python -m pw_status.update_style to migrate to the new
Status::Code() functions from the Status::CODE variables.
Change-Id: I8757cf1f46586c04cd822c01f9868de7d3ea0583
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/24481
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
Reviewed-by: Ewout van Bekkum <ewout@google.com>
diff --git a/pw_blob_store/blob_store.cc b/pw_blob_store/blob_store.cc
index 2389292..bd68285 100644
--- a/pw_blob_store/blob_store.cc
+++ b/pw_blob_store/blob_store.cc
@@ -468,9 +468,7 @@
Status status = kvs_.Delete(MetadataKey());
- return (status == OkStatus() || status == Status::NotFound())
- ? OkStatus()
- : Status::Internal();
+ return (status.ok() || status.IsNotFound()) ? OkStatus() : Status::Internal();
}
Status BlobStore::ValidateChecksum() {
diff --git a/pw_blob_store/blob_store_test.cc b/pw_blob_store/blob_store_test.cc
index dcb4bff..e5ff2f1 100644
--- a/pw_blob_store/blob_store_test.cc
+++ b/pw_blob_store/blob_store_test.cc
@@ -220,7 +220,7 @@
EXPECT_EQ(OkStatus(), writer.Write(tmp_buffer));
// The write does an implicit erase so there should be no key for this blob.
- EXPECT_EQ(Status::NOT_FOUND,
+ EXPECT_EQ(Status::NotFound(),
kvs::TestKvs().Get(blob_title, tmp_buffer).status());
EXPECT_EQ(OkStatus(), writer.Close());
@@ -230,7 +230,7 @@
EXPECT_EQ(OkStatus(), writer.Discard());
EXPECT_EQ(OkStatus(), writer.Close());
- EXPECT_EQ(Status::NOT_FOUND,
+ EXPECT_EQ(Status::NotFound(),
kvs::TestKvs().Get(blob_title, tmp_buffer).status());
}
diff --git a/pw_cpu_exception_armv7m/proto_dump.cc b/pw_cpu_exception_armv7m/proto_dump.cc
index ea6774e..cc71733 100644
--- a/pw_cpu_exception_armv7m/proto_dump.cc
+++ b/pw_cpu_exception_armv7m/proto_dump.cc
@@ -55,8 +55,8 @@
// reflected here.
Status status = state_encoder.WriteR12(cpu_state.base.r12);
if (!status.ok()) {
- return status == Status::ResourceExhausted() ? Status::ResourceExhausted()
- : Status::Unknown();
+ return status.IsResourceExhausted() ? Status::ResourceExhausted()
+ : Status::Unknown();
}
return OkStatus();
}
diff --git a/pw_hdlc/py/decode_test.py b/pw_hdlc/py/decode_test.py
index fd2ebf7..e5da8d5 100755
--- a/pw_hdlc/py/decode_test.py
+++ b/pw_hdlc/py/decode_test.py
@@ -165,7 +165,7 @@
if frame.ok():
yield f' Frame(kDecodedFrame{i:02}),'
else:
- yield f' Status::DATA_LOSS, // Frame {i}'
+ yield f' Status::DataLoss(), // Frame {i}'
_CPP_HEADER = """\
@@ -223,7 +223,7 @@
auto& expected = kExpected[decoded_frames - 1];
if (std::holds_alternative<Status>(expected)) {{
- EXPECT_EQ(Status::DATA_LOSS, result.status());
+ EXPECT_EQ(Status::DataLoss(), result.status());
}} else {{
ASSERT_EQ(OkStatus(), result.status());
diff --git a/pw_kvs/key_value_store.cc b/pw_kvs/key_value_store.cc
index 6c2a1a6..9823ae9 100644
--- a/pw_kvs/key_value_store.cc
+++ b/pw_kvs/key_value_store.cc
@@ -102,7 +102,7 @@
Status recovery_status = FixErrors();
if (recovery_status.ok()) {
- if (metadata_result == Status::OutOfRange()) {
+ if (metadata_result.IsOutOfRange()) {
internal_stats_.missing_redundant_entries_recovered =
pre_fix_redundancy_errors;
INF("KVS init: Redundancy level successfully updated");
@@ -110,7 +110,7 @@
WRN("KVS init: Corruption detected and fully repaired");
}
initialized_ = InitializationState::kReady;
- } else if (recovery_status == Status::ResourceExhausted()) {
+ } else if (recovery_status.IsResourceExhausted()) {
WRN("KVS init: Unable to maintain required free sector");
} else {
WRN("KVS init: Corruption detected and unable repair");
@@ -169,7 +169,7 @@
Address next_entry_address;
Status status = LoadEntry(entry_address, &next_entry_address);
- if (status == Status::NotFound()) {
+ if (status.IsNotFound()) {
DBG("Hit un-written data in sector; moving to the next sector");
break;
} else if (!status.ok()) {
@@ -437,7 +437,7 @@
return WriteEntryForExistingKey(metadata, EntryState::kValid, key, value);
}
- if (status == Status::NotFound()) {
+ if (status.IsNotFound()) {
return WriteEntryForNewKey(key, value);
}
@@ -528,7 +528,7 @@
// If the key's hash collides with an existing key or if the key is deleted,
// treat it as if it is not in the KVS.
- if (status == Status::AlreadyExists() ||
+ if (status.IsAlreadyExists() ||
(status.ok() && metadata->state() == EntryState::kDeleted)) {
return Status::NotFound();
}
@@ -747,7 +747,7 @@
bool do_auto_gc = options_.gc_on_write != GargbageCollectOnWrite::kDisabled;
// Do garbage collection as needed, so long as policy allows.
- while (result == Status::ResourceExhausted() && do_auto_gc) {
+ while (result.IsResourceExhausted() && do_auto_gc) {
if (options_.gc_on_write == GargbageCollectOnWrite::kOneSector) {
// If GC config option is kOneSector clear the flag to not do any more
// GC after this try.
@@ -756,7 +756,7 @@
// Garbage collect and then try again to find the best sector.
Status gc_status = GarbageCollect(reserved);
if (!gc_status.ok()) {
- if (gc_status == Status::NotFound()) {
+ if (gc_status.IsNotFound()) {
// Not enough space, and no reclaimable bytes, this KVS is full!
return Status::ResourceExhausted();
}
@@ -1093,7 +1093,7 @@
loop_count++;
// Error of RESOURCE_EXHAUSTED indicates no space found for relocation.
// Reset back to OK for the next pass.
- if (repair_status == Status::ResourceExhausted()) {
+ if (repair_status.IsResourceExhausted()) {
repair_status = OkStatus();
}
@@ -1104,8 +1104,7 @@
Status sector_status = GarbageCollectSector(sector, {});
if (sector_status.ok()) {
internal_stats_.corrupt_sectors_recovered += 1;
- } else if (repair_status.ok() ||
- repair_status == Status::ResourceExhausted()) {
+ } else if (repair_status.ok() || repair_status.IsResourceExhausted()) {
repair_status = sector_status;
}
}
diff --git a/pw_kvs/key_value_store_map_test.cc b/pw_kvs/key_value_store_map_test.cc
index 0ae42f3..947a3fa 100644
--- a/pw_kvs/key_value_store_map_test.cc
+++ b/pw_kvs/key_value_store_map_test.cc
@@ -270,7 +270,7 @@
EXPECT_EQ(Status::InvalidArgument(), result);
} else if (map_.size() == kvs_.max_size()) {
EXPECT_EQ(Status::ResourceExhausted(), result);
- } else if (result == Status::ResourceExhausted()) {
+ } else if (result.IsResourceExhausted()) {
EXPECT_FALSE(map_.empty());
} else if (result.ok()) {
map_[key] = value;
@@ -302,7 +302,7 @@
}
deleted_.insert(key);
- } else if (result == Status::ResourceExhausted()) {
+ } else if (result.IsResourceExhausted()) {
PW_LOG_WARN("Delete: RESOURCE_EXHAUSTED could not delete key %s",
key.c_str());
} else {
diff --git a/pw_log_multisink/log_queue_test.cc b/pw_log_multisink/log_queue_test.cc
index b9243b5..fc75706 100644
--- a/pw_log_multisink/log_queue_test.cc
+++ b/pw_log_multisink/log_queue_test.cc
@@ -184,7 +184,7 @@
std::byte log_buffer[kLogBufferSize];
LogQueueWithEncodeBuffer<kSmallBuffer> log_queue(log_buffer);
- EXPECT_EQ(Status::INTERNAL,
+ EXPECT_EQ(Status::Internal(),
log_queue.PushTokenizedMessage(
std::as_bytes(std::span(kTokenizedMessage)),
kFlags,
@@ -202,7 +202,7 @@
std::byte log_buffer[kLogBufferSize];
LogQueueWithEncodeBuffer<kEncodeBufferSize> log_queue_small(
std::span(log_buffer, kSmallerThanPreamble));
- EXPECT_EQ(Status::OUT_OF_RANGE,
+ EXPECT_EQ(Status::OutOfRange(),
log_queue_small.PushTokenizedMessage(
std::as_bytes(std::span(kTokenizedMessage)),
kFlags,
@@ -222,7 +222,7 @@
kTokenizedThread,
kTimestamp);
}
- EXPECT_EQ(Status::RESOURCE_EXHAUSTED,
+ EXPECT_EQ(Status::ResourceExhausted(),
log_queue_medium.PushTokenizedMessage(
std::as_bytes(std::span(kTokenizedMessage)),
kFlags,
diff --git a/pw_protobuf/decoder.cc b/pw_protobuf/decoder.cc
index 332f49a..813046c 100644
--- a/pw_protobuf/decoder.cc
+++ b/pw_protobuf/decoder.cc
@@ -242,7 +242,7 @@
// Iterate the proto, calling the handler with each field number.
while (state_ == kDecodeInProgress) {
if (Status status = decoder_.Next(); !status.ok()) {
- if (status == Status::OutOfRange()) {
+ if (status.IsOutOfRange()) {
// Reached the end of the proto.
break;
}
@@ -253,7 +253,7 @@
Status status = handler_->ProcessField(*this, decoder_.FieldNumber());
if (!status.ok()) {
- state_ = status == Status::Cancelled() ? kDecodeCancelled : kDecodeFailed;
+ state_ = status.IsCancelled() ? kDecodeCancelled : kDecodeFailed;
return status;
}
diff --git a/pw_rpc/packet.cc b/pw_rpc/packet.cc
index 9b62a4f..3739370 100644
--- a/pw_rpc/packet.cc
+++ b/pw_rpc/packet.cc
@@ -62,7 +62,7 @@
}
}
- if (status == Status::DataLoss()) {
+ if (status.IsDataLoss()) {
return status;
}
diff --git a/pw_status/status_test.cc b/pw_status/status_test.cc
index f6ca551..d28017c 100644
--- a/pw_status/status_test.cc
+++ b/pw_status/status_test.cc
@@ -49,7 +49,7 @@
TEST(Status, ConstructWithStatusCode) {
constexpr Status status(PW_STATUS_ABORTED);
- static_assert(Status::Aborted() == status);
+ static_assert(status.IsAborted());
}
TEST(Status, AssignFromStatusCode) {
diff --git a/pw_trace_tokenized/public/pw_trace_tokenized/trace_tokenized.h b/pw_trace_tokenized/public/pw_trace_tokenized/trace_tokenized.h
index 56516e3..34d9456 100644
--- a/pw_trace_tokenized/public/pw_trace_tokenized/trace_tokenized.h
+++ b/pw_trace_tokenized/public/pw_trace_tokenized/trace_tokenized.h
@@ -63,7 +63,7 @@
const void* data_buffer,
size_t data_size) {
if (IsFull()) {
- return pw::Status::RESOURCE_EXHAUSTED;
+ return pw::Status::ResourceExhausted();
}
event_queue_[head_].trace_token = trace_token;
event_queue_[head_].event_type = event_type;
diff --git a/pw_trace_tokenized/trace_test.cc b/pw_trace_tokenized/trace_test.cc
index 104dce8..ceaa4b2 100644
--- a/pw_trace_tokenized/trace_test.cc
+++ b/pw_trace_tokenized/trace_test.cc
@@ -583,7 +583,7 @@
EXPECT_FALSE(queue.IsEmpty());
EXPECT_TRUE(queue.IsFull());
EXPECT_EQ(queue.TryPushBack(QUEUE_TESTS_ARGS(1)),
- pw::Status::RESOURCE_EXHAUSTED);
+ pw::Status::ResourceExhausted());
for (size_t i = 0; i < kQueueSize; i++) {
EXPECT_TRUE(QUEUE_CHECK_RESULT(kQueueSize, queue.PeekFront(), i));