code: @SneakyThrows
      public static <T> T executeGroovyScript(final GroovyObject groovyObject,
                                              final String methodName,
                                              final Object[] args,
                                              final Class<T> clazz,
                                              final boolean failOnError) {
          try {
              LOGGER.trace("Executing groovy script's [{}] method, with parameters [{}]", methodName, args);
              val result = groovyObject.invokeMethod(methodName, args);
              LOGGER.trace("Results returned by the groovy script are [{}]", result);
  
              if (!clazz.equals(Void.class)) {
                  return getGroovyScriptExecutionResultOrThrow(clazz, result);
              }
          } catch (final Exception e) {
              var cause = (Throwable) null;
              if (e instanceof InvokerInvocationException) {
                  cause = e.getCause();
              } else {
                  cause = e;
              }
              if (failOnError) {
                  throw cause;
              }
              LOGGER.error(cause.getMessage(), cause);
          }
          return null;
      }
docs: Execute groovy script t.
  
  @param <T>          the type parameter
  @param groovyObject the groovy object
  @param methodName   the method name
  @param args         the args
  @param clazz        the clazz
  @param failOnError  the fail on error
  @return the t