This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Add error handling (elog) in code completion.
ClosedPublic

Authored by adamcz on Dec 14 2020, 8:07 AM.

Diff Detail

Event Timeline

adamcz created this revision.Dec 14 2020, 8:07 AM
adamcz requested review of this revision.Dec 14 2020, 8:07 AM
njames93 added inline comments.
clang-tools-extra/clangd/CodeComplete.cpp
187–188

This can stay as 1 line, The condition variable in an if has lifetime throughout the then/else branch.

sammccall added inline comments.Dec 15 2020, 12:34 AM
clang-tools-extra/clangd/CodeComplete.cpp
192

I think this is too noisy.

We can hit this in "normal" cases of certain projects.
For better or worse, we don't currently filter out index results where we know the responsible header and can't include it (because it's not under any include path entry). In these cases toHeaderFile() returns an error.

Since this can happen in the normal case for *each* completion candidate (default 100), and completion requests are very frequent, this could dominate log output in affected projects.

It *might* be OK at vlog? I get the desire to not silence errors here. I think the question is what are the error cases we're *trying* to call out loudly. Maybe we can separate out the "shouldn't happen" vs the "fairly expected" cases.
(Even then there's the prospect that this is either going to not fire or fire dozens of times, which is a little sad)

adamcz updated this revision to Diff 312206.Dec 16 2020, 7:13 AM
adamcz marked an inline comment as done.

address comments

adamcz added inline comments.Dec 16 2020, 7:15 AM
clang-tools-extra/clangd/CodeComplete.cpp
192

Originally I didn't even log here. We do this expansion at other places and they may log already, I don't think it's critical to log here. Kadir pointed out error needs to be handled or it will assert()-fail (that one place returns Expected rather than Optional, I missed that), which is the motivation for this change.

I made it vlog, but if you think it's too spammy I can remove it and just ignore the error (by this time explicitly, so it doesn't crash). I don't think we'll see these errors often - this only happens when we failed to parse the URI or recognize the scheme, which basically can only happen with remote index and some kind of version skew or corrupt data, so I'm fine with vlog() I think.

sammccall accepted this revision.Dec 16 2020, 9:07 AM
sammccall added inline comments.
clang-tools-extra/clangd/CodeComplete.cpp
192

Oh wow, I totally missed that the Expected was unhandled before!

Yeah let's go with vlog.
(If you like, downgrading the log() to vlog() for the callsite in CodeComplete.cpp seems like a good idea)

This revision is now accepted and ready to land.Dec 16 2020, 9:07 AM
This revision was landed with ongoing or failed builds.Dec 28 2020, 6:23 AM
This revision was automatically updated to reflect the committed changes.