-
Notifications
You must be signed in to change notification settings - Fork 481
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
Throw a consistent error object from makedocs on user errors #2326
base: master
Are you sure you want to change the base?
Conversation
I vaguely remember there being a way to discard the “caused by” information… let me look into that later tonight. |
I must be misremembering… or at least I can't figure out how to directly manipulate the exception stack or suppress the "caused by" message. Having the "caused by" show up like that definitely defeats the purpose, though. I think throwing outside of the If you really want to preserve the full original backtrace, the best I've been able to come up with this the following: function makedocs(; debug = false, format = HTML(), kwargs...)
exception = nothing
try
document = Documenter.Document(; format=format, kwargs...)
# Before starting the build pipeline, we empty out the subtype cache used by
# Selectors.dispatch. This is to make sure that we pick up any new selector stages that
# may have been added to the selector pipelines between makedocs calls.
empty!(Selectors.selector_subtypes)
cd(document.user.root) do
withenv(NO_KEY_ENV...) do
Selectors.dispatch(Builder.DocumentPipeline, document)
end
end
return debug ? document : nothing
catch e
if isa(e, DocumenterBuildException)
exc_error_log = IOBuffer()
showerror(exc_error_log, e, catch_backtrace())
@error String(take!(exc_error_log)) # XXX: better: @debug
exception = DocumenterError(:makedocs, (e, catch_backtrace()))
else
rethrow(e)
end
end
isnothing(exception) || throw(exception)
end For the test case I was playing with (an intentional error in the citations), it produces the following output● goerz@ophelia master:~/Documents/Programming/DocumenterCitations.jl> make docs julia --project=test docs/make.jl Starting makedocs [ Info: SetupBuildDirectory: setting up build directory. [ Info: Doctest: running doctests. [ Info: ExpandTemplates: expanding markdown templates. [ Info: CollectCitations ┌ Error: Key "xxxGoerzQ2022" not found in entries from /Users/goerz/Documents/Programming/DocumenterCitations.jl/docs/src/refs.bib └ @ DocumenterCitations ~/Documents/Programming/DocumenterCitations.jl/src/collect_citations.jl:92 [ Info: ExpandBibliography: expanding `@bibliography` blocks. [ Info: ExpandCitations ┌ Error: expand_citation: No destination for key="xxxGoerzQ2022" → unlinked text "GoerzQ2022" └ @ DocumenterCitations ~/Documents/Programming/DocumenterCitations.jl/src/expand_citations.jl:139 [ Info: CrossReferences: building cross-references. [ Info: CheckDocument: running document checks. [ Info: Populate: populating indices. ┌ Error: DocCheckError: `makedocs` encountered an error [:citations] -- terminating build before rendering. │ │ Stacktrace: │ [1] runner(#unused#::Type{Documenter.Builder.RenderDocument}, doc::Documenter.Document) │ @ Documenter ~/Documents/Programming/Documenter.jl/src/builder_pipeline.jl:258 │ [2] dispatch(#unused#::Type{Documenter.Builder.DocumentPipeline}, x::Documenter.Document) │ @ Documenter.Selectors ~/Documents/Programming/Documenter.jl/src/utilities/Selectors.jl:170 │ [3] #79 │ @ ~/Documents/Programming/Documenter.jl/src/makedocs.jl:258 [inlined] │ [4] withenv(::Documenter.var"#79#81"{Documenter.Document}, ::Pair{String, Nothing}, ::Vararg{Pair{String, Nothing}}) │ @ Base ./env.jl:197 │ [5] #78 │ @ ~/Documents/Programming/Documenter.jl/src/makedocs.jl:257 [inlined] │ [6] cd(f::Documenter.var"#78#80"{Documenter.Document}, dir::String) │ @ Base.Filesystem ./file.jl:112 │ [7] makedocs(; debug::Bool, format::Documenter.HTMLWriter.HTML, kwargs::Base.Pairs{Symbol, Any, NTuple{6, Symbol}, NamedTuple{(:authors, :linkcheck, :warnonly, :sitename, :pages, :plugins), Tuple{String, Bool, Vector{Symbol}, String, Vector{Pair{String, String}}, Vector{CitationBibliography}}}}) │ @ Documenter ~/Documents/Programming/Documenter.jl/src/makedocs.jl:256 │ [8] top-level scope │ @ ~/Documents/Programming/DocumenterCitations.jl/docs/make.jl:21 │ [9] include(mod::Module, _path::String) │ @ Base ./Base.jl:457 │ [10] exec_options(opts::Base.JLOptions) │ @ Base ./client.jl:307 │ [11] _start() │ @ Base ./client.jl:522 └ @ Documenter ~/Documents/Programming/Documenter.jl/src/makedocs.jl:265 ERROR: LoadError: DocumenterError (makedocs): Documenter build failed to complete. Underlying exception: DocCheckError: `makedocs` encountered an error [:citations] -- terminating build before rendering. Please check the error logs above as well. Stacktrace: [1] makedocs(; debug::Bool, format::Documenter.HTMLWriter.HTML, kwargs::Base.Pairs{Symbol, Any, NTuple{6, Symbol}, NamedTuple{(:authors, :linkcheck, :warnonly, :sitename, :pages, :plugins), Tuple{String, Bool, Vector{Symbol}, String, Vector{Pair{String, String}}, Vector{CitationBibliography}}}}) @ Documenter ~/Documents/Programming/Documenter.jl/src/makedocs.jl:272 [2] top-level scope @ ~/Documents/Programming/DocumenterCitations.jl/docs/make.jl:21 in expression starting at /Users/goerz/Documents/Programming/DocumenterCitations.jl/docs/make.jl:21 make: *** [Makefile:36: docs] Error 1 ``` Having the "caused by" info earlier in an |
Inspired by JuliaDocs/DocumenterCitations.jl#59 (comment):
The doccheck error would now print as:
I was hoping it would clean things up a bit (the main error stracktrace just shows
makedocs
-- best we can do I think). But thecaused by
might be confusing now.. and it's kinda duplicated in theshowerror
I added. We could get rid of it bythrow
ing outside of thecatch
, but it feels like it would be good to somehow retain some information about the inner error. Leaving this as a draft for now -- would appreciate any thoughts on this!cc @goerz