Skip to content

Commit 0624204

Browse files
christollidayfacebook-github-bot
authored andcommitted
Write string tags to invocation record
Summary: Can be useful to have these in error_tags and not just the category key. Since this requires storing these in ErrorReport it also means these won't be dropped if string tags are added to command errors or daemon errors, although this is not currently used. Reviewed By: iguridi Differential Revision: D71156099 fbshipit-source-id: 58f19c7b91399befd7e04315206d24d877c7a768
1 parent 40fef2c commit 0624204

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

app/buck2_client_ctx/src/subscribers/recorder.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -1649,20 +1649,24 @@ fn process_error_report(error: buck2_data::ErrorReport) -> buck2_data::Processed
16491649
Tier::Environment => ENVIRONMENT.to_owned(),
16501650
Tier::Input => INPUT.to_owned(),
16511651
};
1652+
let tags = error
1653+
.tags
1654+
.iter()
1655+
.copied()
1656+
.filter_map(|v| buck2_data::error::ErrorTag::try_from(v).ok())
1657+
.map(|t| t.as_str_name().to_owned());
1658+
1659+
let string_tags = error.string_tags.iter().map(|t| t.tag.clone());
1660+
let tags = tags.chain(string_tags).collect();
1661+
16521662
buck2_data::ProcessedErrorReport {
16531663
tier: None,
16541664
message: error.message,
16551665
telemetry_message: error.telemetry_message,
16561666
source_location: error
16571667
.source_location
16581668
.map(|s| SourceLocation::from(s).to_string()),
1659-
tags: error
1660-
.tags
1661-
.iter()
1662-
.copied()
1663-
.filter_map(|v| buck2_data::error::ErrorTag::try_from(v).ok())
1664-
.map(|t| t.as_str_name().to_owned())
1665-
.collect(),
1669+
tags,
16661670
best_tag: Some(best_tag),
16671671
sub_error_categories: error.sub_error_categories,
16681672
category_key: error.category_key,

app/buck2_data/data.proto

+4
Original file line numberDiff line numberDiff line change
@@ -2400,6 +2400,9 @@ message ErrorReport {
24002400
optional string type_name = 2;
24012401
optional uint32 source_line = 3;
24022402
}
2403+
message StringTag {
2404+
string tag = 1;
2405+
}
24032406

24042407
reserved 1, 2;
24052408
// The error message that is shown to users on the CLI
@@ -2416,6 +2419,7 @@ message ErrorReport {
24162419
repeated buck.data.error.ErrorTag tags = 6;
24172420
repeated string sub_error_categories = 7;
24182421
optional string category_key = 8;
2422+
repeated StringTag string_tags = 9;
24192423
}
24202424

24212425
// Identical to `ErrorReport`, but with the tags converted to strings.

app/buck2_error/src/conversion/report.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
use buck2_data::ErrorReport;
1111

12+
use crate::context_value::ContextValue;
13+
use crate::context_value::StringTag;
1214
use crate::source_location::SourceLocation;
1315
use crate::ErrorTag;
1416

@@ -23,7 +25,8 @@ impl From<ErrorReport> for crate::Error {
2325
.into_iter()
2426
.filter_map(|v| ErrorTag::try_from(v).ok())
2527
.collect();
26-
crate::Error::new(
28+
29+
let mut error = crate::Error::new(
2730
value.message.clone(),
2831
*tags.first().unwrap_or(&ErrorTag::Tier0),
2932
value
@@ -32,7 +35,13 @@ impl From<ErrorReport> for crate::Error {
3235
.unwrap_or(SourceLocation::new(file!())),
3336
None,
3437
)
35-
.tag(tags)
38+
.tag(tags);
39+
40+
for tag in value.string_tags {
41+
let tag = ContextValue::StringTag(StringTag { tag: tag.tag });
42+
error = error.context(tag);
43+
}
44+
error
3645
}
3746
}
3847

@@ -64,12 +73,22 @@ impl From<&crate::Error> for ErrorReport {
6473
} else {
6574
vec![]
6675
};
76+
let string_tags = err
77+
.iter_context()
78+
.filter_map(|kind| match kind {
79+
ContextValue::StringTag(val) => Some(buck2_data::error_report::StringTag {
80+
tag: val.tag.clone(),
81+
}),
82+
_ => None,
83+
})
84+
.collect();
6785

6886
buck2_data::ErrorReport {
6987
message,
7088
telemetry_message,
7189
source_location: Some(err.source_location().clone().into()),
7290
tags: err.tags().iter().map(|t| *t as i32).collect(),
91+
string_tags,
7392
sub_error_categories,
7493
category_key: Some(category_key),
7594
}

tests/core/build/test_error_categorization.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ async def test_daemon_crash(buck: Buck, tmp_path: Path) -> None:
217217
else:
218218
assert "stream closed because of a broken pipe" in error["message"]
219219

220-
assert error["tags"] == ["CLIENT_GRPC", "SERVER_PANICKED", "TIER0"]
220+
assert error["tags"][0:3] == ["CLIENT_GRPC", "SERVER_PANICKED", "TIER0"]
221+
assert error["tags"][3].startswith("crash")
221222
assert "buckd stderr:\n" in error["message"]
222223
assert "panicked at" in error["message"]
223224

@@ -282,6 +283,8 @@ async def test_daemon_abort(buck: Buck, tmp_path: Path) -> None:
282283
# TODO dump stack trace on mac and windows
283284
if is_running_on_linux():
284285
assert "crash(" in category_key
286+
# test string tags are in error_tags
287+
assert error["tags"][-1].startswith("crash(")
285288

286289

287290
@buck_test()

0 commit comments

Comments
 (0)