File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 27
27
#include < fmt/format.h>
28
28
29
29
#include " Inspection/VPackSaveInspector.h"
30
+ #include " Inspection/VPackWithErrorT.h"
30
31
#include " Inspection/detail/traits.h"
31
- #include < Inspection/VPack.h>
32
32
33
33
template <>
34
34
struct fmt ::formatter<VPackSlice> {
@@ -77,8 +77,16 @@ struct inspection_formatter : fmt::formatter<VPackSlice> {
77
77
typename Inspector = VPackSaveInspector<NoContext>>
78
78
requires detail::HasInspectOverload<T, Inspector>::value auto format (
79
79
const T& value, FormatContext& ctx) const -> decltype(ctx.out()) {
80
- auto sharedSlice = arangodb::velocypack::serialize (value);
81
- return fmt::formatter<VPackSlice>::format (sharedSlice.slice (), ctx);
80
+ auto sharedSlice = inspection::serializeWithErrorT (value);
81
+ if (not sharedSlice.ok ()) {
82
+ VPackBuilder error;
83
+ {
84
+ VPackObjectBuilder ob (&error);
85
+ error.add (" error" , VPackValue (sharedSlice.error ().error ()));
86
+ }
87
+ return fmt::formatter<VPackSlice>::format (error.slice (), ctx);
88
+ }
89
+ return fmt::formatter<VPackSlice>::format (sharedSlice.get ().slice (), ctx);
82
90
}
83
91
};
84
92
} // namespace arangodb::inspection
Original file line number Diff line number Diff line change @@ -563,7 +563,13 @@ auto inspect(Inspector& f, MyStringEnum& x) {
563
563
return f.enumeration (x).values (MyStringEnum::kValue1 , " value1" , //
564
564
MyStringEnum::kValue2 , " value2" );
565
565
}
566
+ } // namespace
567
+
568
+ template <>
569
+ struct fmt ::formatter<MyStringEnum>
570
+ : arangodb::inspection::inspection_formatter {};
566
571
572
+ namespace {
567
573
enum class MyIntEnum {
568
574
kValue1 ,
569
575
kValue2 ,
@@ -2673,6 +2679,12 @@ TEST_F(VPackInspectionTest, formatter) {
2673
2679
" true,\n \" s\" : \" cheese\"\n }" );
2674
2680
}
2675
2681
2682
+ TEST_F (VPackInspectionTest, formatter_prints_serialization_error) {
2683
+ MyStringEnum val = static_cast <MyStringEnum>(42 );
2684
+ auto def = fmt::format (" {}" , val);
2685
+ ASSERT_EQ (def, R"( {"error":"Unknown enum value 42"})" );
2686
+ }
2687
+
2676
2688
TEST_F (VPackInspectionTest, deserialize) {
2677
2689
velocypack::Builder builder;
2678
2690
builder.openObject ();
You can’t perform that action at this time.
0 commit comments