Skip to content

Commit 4b4b750

Browse files
Improve error message for rich-parameters API when no provisioners are running
When the rich-parameters API endpoint is called and the job hasn't completed, the previous error message 'Job hasn't completed!' was unhelpful and didn't explain why the job was stuck. This change enhances the error handling to: 1. Check if there are any active provisioners for the organization 2. If no active provisioners are found, return a clear error message explaining that provisioners are needed and providing actionable guidance 3. If provisioners are available but the job still hasn't completed, fall back to the original error message The new error message helps users understand that they need to start a provisioner or contact their administrator to resolve template parameter resolution issues. Fixes: #18979 Co-authored-by: angrycub <464492+angrycub@users.noreply.github.com>
1 parent d7b1253 commit 4b4b750

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

coderd/provisionerjobs.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/http"
1010
"sort"
1111
"strconv"
12+
"time"
1213

1314
"github.com/google/uuid"
1415
"golang.org/x/xerrors"
@@ -17,10 +18,12 @@ import (
1718
"github.com/coder/coder/v2/coderd/database"
1819
"github.com/coder/coder/v2/coderd/database/db2sdk"
1920
"github.com/coder/coder/v2/coderd/database/dbauthz"
21+
"github.com/coder/coder/v2/coderd/database/dbtime"
2022
"github.com/coder/coder/v2/coderd/database/pubsub"
2123
"github.com/coder/coder/v2/coderd/httpapi"
2224
"github.com/coder/coder/v2/coderd/httpmw"
2325
"github.com/coder/coder/v2/coderd/httpmw/loggermw"
26+
"github.com/coder/coder/v2/coderd/provisionerdserver"
2427
"github.com/coder/coder/v2/coderd/rbac"
2528
"github.com/coder/coder/v2/coderd/rbac/policy"
2629
"github.com/coder/coder/v2/coderd/util/slice"
@@ -188,6 +191,32 @@ func (api *API) provisionerJobLogs(rw http.ResponseWriter, r *http.Request, job
188191
func (api *API) provisionerJobResources(rw http.ResponseWriter, r *http.Request, job database.ProvisionerJob) {
189192
ctx := r.Context()
190193
if !job.CompletedAt.Valid {
194+
// Check if there are any active provisioners for this organization
195+
daemons, err := api.Database.GetProvisionerDaemonsByOrganization(ctx, database.GetProvisionerDaemonsByOrganizationParams{
196+
OrganizationID: job.OrganizationID,
197+
WantTags: database.StringMap{},
198+
})
199+
if err != nil {
200+
// If we can't check provisioners, fall back to the original error
201+
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
202+
Message: "Job hasn't completed!",
203+
})
204+
return
205+
}
206+
207+
// Check if any provisioners are active (not stale)
208+
now := dbtime.Now()
209+
activeProvisioners := db2sdk.RecentProvisionerDaemons(now, provisionerdserver.StaleInterval, daemons)
210+
211+
if len(activeProvisioners) == 0 {
212+
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
213+
Message: "No provisioners are currently running for this organization. Please start a provisioner or contact your administrator to enable template parameter resolution.",
214+
Detail: "Template parameter resolution requires an active provisioner to process the job.",
215+
})
216+
return
217+
}
218+
219+
// Provisioners are available but job still hasn't completed
191220
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
192221
Message: "Job hasn't completed!",
193222
})

0 commit comments

Comments
 (0)