jenkinsci / configuration-as-code-plugin

Jenkins Configuration as Code Plugin
https://plugins.jenkins.io/configuration-as-code
MIT License
2.7k stars 722 forks source link

Improve error reporting for invalid yaml #2543

Open olivergondza opened 3 months ago

olivergondza commented 3 months ago

What feature do you want to see added?

In some cases, exceptions lack key names, and in all case they lack line number in the file.

Reproducer:

jenkins:
  systemMessage: ["BOOM!"]

Exception:

io.jenkins.plugins.casc.ConfiguratorException: Item isn't a Scalar
    at io.jenkins.plugins.casc.model.CNode.asScalar(CNode.java:29)
    at io.jenkins.plugins.casc.impl.configurators.PrimitiveConfigurator.configure(PrimitiveConfigurator.java:48)
    at io.jenkins.plugins.casc.impl.configurators.PrimitiveConfigurator.check(PrimitiveConfigurator.java:53)
    at io.jenkins.plugins.casc.BaseConfigurator.configure(BaseConfigurator.java:360)
    at io.jenkins.plugins.casc.BaseConfigurator.check(BaseConfigurator.java:293)
    at io.jenkins.plugins.casc.BaseConfigurator.configure(BaseConfigurator.java:360)
    at io.jenkins.plugins.casc.BaseConfigurator.check(BaseConfigurator.java:293)
    at io.jenkins.plugins.casc.ConfigurationAsCode.lambda$checkWith$9(ConfigurationAsCode.java:834)
    at io.jenkins.plugins.casc.ConfigurationAsCode.invokeWith(ConfigurationAsCode.java:777)
    at io.jenkins.plugins.casc.ConfigurationAsCode.checkWith(ConfigurationAsCode.java:834)
    at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:820)
    at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:699)
    at io.jenkins.plugins.casc.ConfigurationAsCode.configure(ConfigurationAsCode.java:356)
    at io.jenkins.plugins.casc.ConfigurationAsCode.init(ConfigurationAsCode.java:345)
Caused: io.jenkins.plugins.casc.ConfigurationAsCodeBootFailure
    at io.jenkins.plugins.casc.ConfigurationAsCode.init(ConfigurationAsCode.java:347)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:109)
    at hudson.init.TaskMethodFinder$TaskImpl.run(TaskMethodFinder.java:185)
    at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:305)
    at jenkins.model.Jenkins$5.runTask(Jenkins.java:1175)
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:221)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:120)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)

In more complex files, these are a pain to find.

Upstream changes

No response