Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7429145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:55:22+00:00 2026-05-29T08:55:22+00:00

What is the standard (or best practice) for Groovy error messages that that shouldn’t

  • 0

What is the standard (or best practice) for Groovy error messages that that shouldn’t span over a certain number of characters/line, e.g., 80 characters?

Consider the following (which is working fine)

throw new IOException("""\
        A Jenkins configuration for the given version control
        system (${vcs.name}) does not exist."""
        .stripIndent()
        .replaceAll('\n', ' '))

This will result in a one-line error message with no indention characters (what I want). But is there some other way (“the Groovy way of doing it”) how to achieve this? If not, how could you add such a method to the GString class in a standalone Groovy application (if found hints regarding a Bootstrap.groovy file but it seems to be related to Grails)?

Example: """Consider a multi line string as shown above""".toSingleLine()

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:55:23+00:00Added an answer on May 29, 2026 at 8:55 am

    You could use the String continuation character then strip multiple spaces:

    throw new IOException( "A Jenkins configuration for the given version control \
                            system (${vcs.name}) does not exist.".replaceAll( /( )\1+/, '$1' ) )
    

    Or you could wrap this in a function and add it to the String.metaClass as I believe the answers you’ve seen point to.

    You’re right in thinking that Bootstrap.groovy is a Grails thing, but if you just set the metaClass early on in your applications lifecycle, you should get the same result…

    String.metaClass.stripRepeatedWhitespace = { delegate.replaceAll( /( )\1+/, '$1' ) }
    

    In saying all this however, I’d probably just keep the message on a single line

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there a standard best practice to show that a form field is mandatory:
What is the best practice (interface and implementation) for a command line tool that
is there a standard or best practice with database table names and fields in
Is there any guideline or standard best practice how to version a software you
If I am authenticating using PAM, is it a standard/best practice to use pam_unix
Are there any standard or best practice ways of limiting feature functionality for a
Is there a standard or best practice for the order of grouping of styles
Is there a best-practice or industry standard for throwing exceptions from a toolkit API?
I am having a very hard time finding a standard pattern / best practice
I'm looking for a best practice/standard pattern for generating feeds in Rails 3. Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.