Skip to content
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

Option to fail on warning #154

Closed
dnault opened this issue Apr 2, 2015 · 12 comments
Closed

Option to fail on warning #154

dnault opened this issue Apr 2, 2015 · 12 comments
Labels
2.x Issue related to the 2.x series enhancement
Milestone

Comments

@dnault
Copy link

dnault commented Apr 2, 2015

I'd like to fail the build when AsciiDoctor issues a warning. To reproduce, process a document with an include directive for a non-existent file, like:

include::doesNotExist.txt[]

@rhaendel
Copy link

+1

@aalmiray
Copy link
Member

@mojavelinux @lordofthejars : we would need asciidoctor to bubble up the waring through asciidoctorj so that the plugin can configure it. Does asciidoctor (ruby) have a message/logger handler already? perhaps we just need to expose it through asciidoctorj

@ysb33r
Copy link
Member

ysb33r commented Apr 13, 2015

We should actually have this as an option in asciidoctor itself, so that asciidoctorj (and such the plugin) can just set it. The failure will then be handled automatically in the same way that it is handled by the plugin today.

@mojavelinux
Copy link
Member

This is already planned in Asciidoctor core. We shouldn't try to patch a solution until we get it solved there. Then it becomes a simple matter of reading the message stack and failing if it contains violations. See asciidoctor/asciidoctor#44.

@mojavelinux
Copy link
Member

This issue should be marked as "tracking". I like to have to label in the issue tracker for this reason.

@otrosien
Copy link

I have an intermediate workaround for this problem: Add a stdout listener on the asciidoctor task, and check for "WARNING", or in my case, for missing include files. Not something to be put into this plugin, actually, but I'll add it here so people can bridge the gap until this feature is supported.

asciidoctor {
            ext.capturedOutput = [ ]
            def listener = { ext.capturedOutput << it } as StandardOutputListener

            logging.addStandardErrorListener(listener)
            logging.addStandardOutputListener(listener)

            doLast {
                logging.removeStandardOutputListener(listener)
                logging.removeStandardErrorListener(listener)
                ext.capturedOutput.join('').with { output ->
                    if (output =~ /include file not found:/) {
                        throw new RuntimeException("Include file(s) not found.\n" + output)
                    }
                }
            }
}

@mojavelinux
Copy link
Member

Very good. This is exactly how this should be solved in the interim. I agree that putting it into the plugin or in AsciidoctorJ is too risky. But putting it in the build configuration is both safe and transparent.

Perhaps we can add this to one of the examples in asciidoctor-gradle-examples.

@otrosien
Copy link

courtesy of Kimble at stackoverflow, btw. http://stackoverflow.com/questions/31523166/gradle-capturing-output-written-to-out-err-on-a-per-task-basis

There seems to be an issue with parallel task execution mentioned there, which I haven't tried to reproduce, as I'm not executing asciidoctor tasks in parallel.

@vogella
Copy link

vogella commented Nov 17, 2016

For reference, @fap- solved this for our build via vogellacompany/com.vogella.gradle.plugins@7a286f7

@ysb33r
Copy link
Member

ysb33r commented Jul 1, 2018

Now that we have the LogHandler in AsciidoctorJ (1.5.7, 1.6.0-alpha.7) we can probably deal with this. I'll look to see if I can add this to 2.0.x development.

@ysb33r ysb33r added enhancement 2.x Issue related to the 2.x series and removed tracking labels Jul 1, 2018
@ysb33r ysb33r added this to the 2.0.0 milestone Jul 1, 2018
@ysb33r ysb33r mentioned this issue Jul 2, 2018
28 tasks
ysb33r added a commit to ysb33r/asciidoctor-gradle-plugin that referenced this issue Jul 17, 2018
- Proper logging using Log4J has been implemented for workers.
- Logging for JavaExec goes to stdout which is then picked up via
  the JavaExec process.
- The `asciidoctorj` extension can be configured to recognise certain
  messages as fatal errors via the `fatalWarnings` methods.
- `missingIncludes` is a helper method that can be passed to the
  `setFatalWarnings` or `fatalWarnings` methods for the common use case
  of missing includes.
@ysb33r
Copy link
Member

ysb33r commented Jul 17, 2018

The code for this will be merged from PR #251 and be available in 2.0-alpha.3

To cover the exact case of this issue the global or task exteniosn can be configured as

asciidoctorj {
   fatalWarnings missingIncludes()
}

More generically any pattern can be supplied, for instance

asciidoctorj {
   fatalWarnings ~/include file not found|missing callout/
}

@ysb33r ysb33r closed this as completed Jul 17, 2018
ysb33r added a commit to ysb33r/asciidoctor-gradle-plugin that referenced this issue Jul 17, 2018
- Proper logging using Log4J has been implemented for workers.
- Logging for JavaExec goes to stdout which is then picked up via
  the JavaExec process.
- The `asciidoctorj` extension can be configured to recognise certain
  messages as fatal errors via the `fatalWarnings` methods.
- `missingIncludes` is a helper method that can be passed to the
  `setFatalWarnings` or `fatalWarnings` methods for the common use case
  of missing includes.
ysb33r added a commit to ysb33r/asciidoctor-gradle-plugin that referenced this issue Jul 17, 2018
- Proper logging using Log4J has been implemented for workers.
- Logging for JavaExec goes to stdout which is then picked up via
  the JavaExec process.
- The `asciidoctorj` extension can be configured to recognise certain
  messages as fatal errors via the `fatalWarnings` methods.
- `missingIncludes` is a helper method that can be passed to the
  `setFatalWarnings` or `fatalWarnings` methods for the common use case
  of missing includes.
@adamu
Copy link

adamu commented Aug 26, 2020

Kotlin:

tasks {
    asciidoctor {
        asciidoctorj {
            fatalWarnings(listOf(missingIncludes()))
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Issue related to the 2.x series enhancement
Projects
None yet
Development

No branches or pull requests

8 participants