Skip to content

Commit fb7e59f

Browse files
committed
Corpus lookup returns Expected
#improvement
1 parent 43973cb commit fb7e59f

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

include/mrdocs/Corpus.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ class MRDOCS_VISIBLE
9090
/** Return the Info for the matching string in a given context.
9191
*/
9292
virtual
93-
Info const*
93+
Expected<Info const*>
9494
lookup(SymbolID const& context, std::string_view name) const = 0;
9595

9696
/** Return the Info for the matching string in the global context.
9797
*/
98-
Info const*
98+
Expected<Info const*>
9999
lookup(std::string_view name) const
100100
{
101101
return lookup(SymbolID::global, name);

src/lib/Lib/CorpusImpl.cpp

+24-8
Original file line numberDiff line numberDiff line change
@@ -221,22 +221,22 @@ isTransparent(Info const& info)
221221
}
222222
}
223223

224-
Info const*
224+
Expected<Info const*>
225225
CorpusImpl::
226-
lookup(SymbolID const& context, std::string_view name) const
226+
lookup(SymbolID const& context, std::string_view const name) const
227227
{
228228
return lookupImpl(*this, context, name);
229229
}
230230

231-
Info const*
231+
Expected<Info const*>
232232
CorpusImpl::
233233
lookup(SymbolID const& context, std::string_view name)
234234
{
235235
return lookupImpl(*this, context, name);
236236
}
237237

238238
template <class Self>
239-
Info const*
239+
Expected<Info const*>
240240
CorpusImpl::
241241
lookupImpl(Self&& self, SymbolID const& context, std::string_view name)
242242
{
@@ -246,16 +246,33 @@ lookupImpl(Self&& self, SymbolID const& context, std::string_view name)
246246
}
247247
if (auto [info, found] = self.lookupCacheGet(context, name); found)
248248
{
249+
if (!info)
250+
{
251+
return Unexpected(formatError(
252+
"Failed to find '{}' from context '{}'",
253+
name,
254+
self.Corpus::qualifiedName(*self.find(context))));
255+
}
249256
return info;
250257
}
251258
Expected<ParsedRef> const s = parseRef(name);
252259
if (!s)
253260
{
254-
report::warn("Failed to parse '{}'\n {}", name, s.error().reason());
255-
self.lookupCacheSet(context, name, nullptr);
256-
return nullptr;
261+
return Unexpected(formatError("Failed to parse '{}'\n {}", name, s.error().reason()));
257262
}
258263
Info const* res = lookupImpl(self, context, *s, name, false);
264+
if (!res)
265+
{
266+
auto const contextPtr = self.find(context);
267+
if (!contextPtr)
268+
{
269+
return Unexpected(formatError("Failed to find '{}'", context));
270+
}
271+
return Unexpected(formatError(
272+
"Failed to find '{}' from context '{}'",
273+
name,
274+
self.Corpus::qualifiedName(*contextPtr)));
275+
}
259276
return res;
260277
}
261278

@@ -600,7 +617,6 @@ CorpusImpl::finalize()
600617
report::debug("Finalizing javadoc");
601618
JavadocFinalizer finalizer(*this);
602619
finalizer.build();
603-
finalizer.emitWarnings();
604620
}
605621

606622

src/lib/Lib/CorpusImpl.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ class CorpusImpl final : public Corpus
9191
Info const*
9292
find(SymbolID const& id) const noexcept override;
9393

94-
Info const*
94+
Expected<Info const*>
9595
lookup(SymbolID const& context, std::string_view name) const override;
9696

97-
Info const*
97+
Expected<Info const*>
9898
lookup(SymbolID const& context, std::string_view name);
9999

100100
/** Build metadata for a set of translation units.
@@ -141,7 +141,7 @@ class CorpusImpl final : public Corpus
141141

142142
template <class Self>
143143
static
144-
Info const*
144+
Expected<Info const*>
145145
lookupImpl(
146146
Self&& self,
147147
SymbolID const& context,

0 commit comments

Comments
 (0)