When using PropertyState providers, the error reporting could be better


(Dimitar Dimitrov) #1

It takes an eagle eye to pick out that the problem in this exception is that “CodacyUploadTask.commitUuid” has not been set. It would be very helpful if the error message was including the name of the property.

* Exception is:
java.lang.IllegalStateException: No value has been specified for this provider.
	at org.gradle.api.internal.provider.AbstractProvider.get(AbstractProvider.java:29)
	at org.gradle.api.internal.provider.DefaultPropertyState.get(DefaultPropertyState.java:65)
	at org.gradle.api.internal.provider.DefaultPropertyState.get(DefaultPropertyState.java:65)
	at org.gradle.kotlin.dsl.PropertyStateExtensionsKt.getValue(PropertyStateExtensions.kt:29)
	at io.github.ddimtirov.gradle.codacy.CodacyUploadTask.getCommitUuid(CodacyPlugin.kt)
	at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
	at org.gradle.api.internal.project.taskfactory.TaskPropertyInfo$4.create(TaskPropertyInfo.java:99)
	at org.gradle.util.SingleMessageLogger.whileDisabled(SingleMessageLogger.java:217)
	at org.gradle.api.internal.project.taskfactory.TaskPropertyInfo.getValue(TaskPropertyInfo.java:97)
	at org.gradle.api.internal.project.taskfactory.TaskClassValidator.validate(TaskClassValidator.java:78)
	at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:41)
	at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
	at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
	at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
	at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
	at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
	at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)

(Róbert Papp) #2

I just busted my eagle eye I on this, so totally agree, but I don’t think it’s possible. We can create DefaultPropertyState objects willy-nilly, so there’s no way to know if it’s associated to a class field or get/set pair.


(Dimitar Dimitrov) #3

One way would be to add API allowing users to give names to the providers. An extra step would be to do bytecode twiddling to set the name of a provider, every time it appears as RHS value of a field assignment or perhaps only if it doesn’t have a name.

Not trivial nor bulletproof, but doable and helpful. There may be other options that elude me, so I am just highlighting the problem.