Skip to content

Commit 8dfd388

Browse files
authored
Check warnings from asciidoctor before next steps (#1254)
Before this commit we bundled executing `asciidoctor`, `xmllint`, and `xsltproc` together, checking warnings after the whole process succeedes. If any step in the process fails we'd log the errors for *that* *step* and exit non-0. The trouble with this behavior is that we'd throw out the warnings from the previous steps. This is especially bad because the warnings from `asciidoctor` are *much* easier to debug that errors from `xmllint`. This commit causes us to check the warnings after each step. If there are any warnings we log them and exit non-0. This is will effectively prefer warnings from asciidoctor if there are any which should make debugging problems like bad links *much* simpler.
1 parent 389a853 commit 8dfd388

File tree

2 files changed

+50
-14
lines changed

2 files changed

+50
-14
lines changed

integtest/spec/single_book_spec.rb

+18
Original file line numberDiff line numberDiff line change
@@ -738,4 +738,22 @@ def self.convert_with_source_branch_before_context(branch)
738738
LOG
739739
end
740740
end
741+
context 'when a referenced id is missing' do
742+
convert_before do |src, dest|
743+
repo = src.repo_with_index 'src', <<~ASCIIDOC
744+
<<missing-ref>>
745+
ASCIIDOC
746+
dest.prepare_convert_single("#{repo.root}/index.asciidoc", '.')
747+
.asciidoctor
748+
.convert(expect_failure: true)
749+
end
750+
it 'fails with an appropriate error status' do
751+
expect(statuses[0]).to eq(255)
752+
end
753+
it 'logs the missing file' do
754+
expect(outputs[0]).to include(<<~LOG.strip)
755+
asciidoctor: WARNING: invalid reference: missing-ref
756+
LOG
757+
end
758+
end
741759
end

lib/ES/Util.pm

+32-14
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,29 @@ sub build_chunked {
125125
docinfo($index),
126126
$index
127127
);
128-
if ( !$lenient ) {
129-
$output .= _xml_lint($dest_xml);
130-
}
131-
$output .= run(
128+
1;
129+
} or do { $output = $@; $died = 1; };
130+
_check_build_error( $output, $died, $lenient );
131+
132+
if ( !$lenient ) {
133+
eval {
134+
$output = _xml_lint($dest_xml);
135+
1;
136+
} or do { $output = $@; $died = 1; };
137+
_check_build_error( $output, $died, $lenient );
138+
}
139+
eval {
140+
$output = run(
132141
'xsltproc',
133142
rawxsltopts(%xsltopts),
134143
'--stringparam', 'base.dir', $chunks_path->absolute . '/',
135144
file('resources/website_chunked.xsl')->absolute,
136145
$dest_xml
137146
);
138-
unlink $dest_xml;
139147
1;
140148
} or do { $output = $@; $died = 1; };
149+
_check_build_error( $output, $died, $lenient );
150+
unlink $dest_xml;
141151
}
142152
else {
143153
my $edit_url = $edit_urls->{$root_dir};
@@ -167,10 +177,9 @@ sub build_chunked {
167177
);
168178
1;
169179
} or do { $output = $@; $died = 1; };
180+
_check_build_error( $output, $died, $lenient );
170181
}
171182

172-
_check_build_error( $output, $died, $lenient );
173-
174183
my ($chunk_dir) = grep { -d and /\.chunked$/ } $raw_dest->children
175184
or die "Couldn't find chunk dir in <$raw_dest>";
176185

@@ -291,19 +300,29 @@ sub build_single {
291300
docinfo($index),
292301
$index
293302
);
294-
if ( !$lenient ) {
295-
$output .= _xml_lint($dest_xml);
296-
}
297-
$output .= run(
303+
1;
304+
} or do { $output = $@; $died = 1; };
305+
_check_build_error( $output, $died, $lenient );
306+
307+
if ( !$lenient ) {
308+
eval {
309+
$output = _xml_lint($dest_xml);
310+
1;
311+
} or do { $output = $@; $died = 1; };
312+
_check_build_error( $output, $died, $lenient );
313+
}
314+
eval {
315+
$output = run(
298316
'xsltproc',
299317
rawxsltopts(%xsltopts),
300318
'--output' => "$raw_dest/index.html",
301319
file('resources/website.xsl')->absolute,
302320
$dest_xml
303321
);
304-
unlink $dest_xml;
305322
1;
306323
} or do { $output = $@; $died = 1; };
324+
_check_build_error( $output, $died, $lenient );
325+
unlink $dest_xml;
307326
}
308327
else {
309328
my $edit_url = $edit_urls->{$root_dir};
@@ -330,10 +349,9 @@ sub build_single {
330349
);
331350
1;
332351
} or do { $output = $@; $died = 1; };
352+
_check_build_error( $output, $died, $lenient );
333353
}
334354

335-
_check_build_error( $output, $died, $lenient );
336-
337355
my $base_name = $index->basename;
338356
$base_name =~ s/\.[^.]+$/.html/;
339357

0 commit comments

Comments
 (0)