-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[lldb][DataFormatters] Change ExtractIndexFromString to return std::optional #138297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -270,10 +270,14 @@ class VectorTypeSyntheticFrontEnd : public SyntheticChildrenFrontEnd { | |
} | ||
|
||
llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name) override { | ||
const char *item_name = name.GetCString(); | ||
uint32_t idx = ExtractIndexFromString(item_name); | ||
if (idx == UINT32_MAX || | ||
(idx < UINT32_MAX && idx >= CalculateNumChildrenIgnoringErrors())) | ||
auto idx_or_err = ExtractIndexFromString(name.AsCString()); | ||
if (!idx_or_err) { | ||
llvm::consumeError(idx_or_err.takeError()); | ||
return llvm::createStringError("Type has no child named '%s'", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my comment above. I would probably just return optional from ExtractIndexFromString, since the error message isn't that useful. But if it were useful, I wanted to point out that we also have llvm::joinErrors() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ended up switching to |
||
name.AsCString()); | ||
} | ||
uint32_t idx = *idx_or_err; | ||
if (idx >= CalculateNumChildrenIgnoringErrors()) | ||
return llvm::createStringError("Type has no child named '%s'", | ||
name.AsCString()); | ||
return idx; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here I would just return a std::optional<>, since all of the StringErrors just say "this failed" without any specific other information, and that's something the caller can also piece together.