Skip to content

Commit f078761

Browse files
NL02copybara-github
authored andcommitted
Set error payload for type inference errors with single spans
PiperOrigin-RevId: 820232578
1 parent 50dc1e1 commit f078761

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

xls/dslx/errors.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ absl::Status TypeInferenceErrorStatusInternal(
4545
if (type_or_annotation != nullptr) {
4646
type_str = type_or_annotation->ToString() + " ";
4747
}
48-
return absl::InvalidArgumentError(
49-
absl::StrFormat("TypeInferenceError: %s %s%s", span.ToString(file_table),
50-
type_str, message));
48+
49+
absl::Status status = absl::InvalidArgumentError(
50+
absl::StrFormat("TypeInferenceError: %s%s", type_str, message));
51+
StatusPayloadProto payload;
52+
*payload.add_spans() = ToProto(span, file_table);
53+
SetStatusPayload(status, payload);
54+
return status;
5155
}
5256

5357
} // namespace

xls/dslx/errors_test.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ TEST(ErrorsTest, TypeInferenceErrorMessage) {
4242
std::unique_ptr<Type> type = BitsType::MakeU32();
4343
absl::Status status = TypeInferenceErrorStatus(
4444
span, type.get(), "this is the message!", file_table);
45-
EXPECT_EQ(
46-
status.ToString(),
47-
"INVALID_ARGUMENT: TypeInferenceError: <no-file>:1:1-2:2 uN[32] this "
48-
"is the message!");
45+
std::optional<StatusPayloadProto> payload = GetStatusPayload(status);
46+
ASSERT_TRUE(payload.has_value());
47+
EXPECT_THAT(payload->spans(),
48+
UnorderedElementsAre(EqualsProto(ToProto(span, file_table))));
49+
EXPECT_EQ(status.message(),
50+
"TypeInferenceError: uN[32] this is the message!");
4951
}
5052

5153
TEST(ErrorsTest, SignednessMismatchErrorAnnotationPayload) {

0 commit comments

Comments
 (0)