From 9c5adab90fffc682a3bfef7da2b90e542643cac1 Mon Sep 17 00:00:00 2001 From: catsby Date: Thu, 3 Aug 2023 15:39:11 -0500 Subject: [PATCH 1/2] Add guards against nil derefernce panics with regards to jobs/tasks and applications --- internal/cli/job_get_stream.go | 1 - internal/cli/job_inspect.go | 18 +++++++++++++++--- internal/cli/job_list.go | 12 +++++++++--- internal/cli/task_inspect.go | 20 ++++++++++++++++---- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/internal/cli/job_get_stream.go b/internal/cli/job_get_stream.go index 8206ba067fe..5b3a9c89719 100644 --- a/internal/cli/job_get_stream.go +++ b/internal/cli/job_get_stream.go @@ -57,7 +57,6 @@ func (c *JobGetStreamCommand) Run(args []string) int { func (c *JobGetStreamCommand) Flags() *flag.Sets { return c.flagSet(flagSetOperation, func(set *flag.Sets) { - //f := set.NewSet("Command Options") }) } diff --git a/internal/cli/job_inspect.go b/internal/cli/job_inspect.go index 5347563e2f5..47c012029c2 100644 --- a/internal/cli/job_inspect.go +++ b/internal/cli/job_inspect.go @@ -169,6 +169,18 @@ func (c *JobInspectCommand) Run(args []string) int { } c.ui.Output("Job Configuration", terminal.WithHeaderStyle()) + appProjectName := resp.GetApplication().GetProject() + if appProjectName == "" { + appProjectName = "deleted" + } + appName := resp.GetApplication().GetApplication() + if appName == "" { + appName = "deleted" + } + workspaceName := resp.GetWorkspace().GetWorkspace() + if workspaceName == "" { + workspaceName = "deleted" + } c.ui.NamedValues([]terminal.NamedValue{ { Name: "ID", Value: resp.Id, @@ -183,13 +195,13 @@ func (c *JobInspectCommand) Run(args []string) int { Name: "Target Runner", Value: targetRunner, }, { - Name: "Workspace", Value: resp.Workspace.Workspace, + Name: "Workspace", Value: workspaceName, }, { - Name: "Project", Value: resp.Application.Project, + Name: "Project", Value: appProjectName, }, { - Name: "Application", Value: resp.Application.Application, + Name: "Application", Value: appName, }, }, terminal.WithInfoStyle()) diff --git a/internal/cli/job_list.go b/internal/cli/job_list.go index 65064b5a686..418272ad97b 100644 --- a/internal/cli/job_list.go +++ b/internal/cli/job_list.go @@ -311,6 +311,12 @@ func (c *JobListCommand) Run(args []string) int { pipeline = "name: " + j.Pipeline.PipelineName + ", run: " + strconv.FormatUint(j.Pipeline.RunSequence, 10) + ", step: " + j.Pipeline.Step } + appProject := j.GetApplication().GetProject() + if appProject == "" { + appProject = "deleted" + } + appWorkspace := j.GetWorkspace().GetWorkspace() + tblColumn := []string{ j.Id, op, @@ -318,13 +324,13 @@ func (c *JobListCommand) Run(args []string) int { queueTime, completeTime, targetRunner, - j.Application.Project, - j.Workspace.Workspace, + appProject, + appWorkspace, } if c.flagVerbose { tblColumn = append(tblColumn, []string{ - j.Application.Application, + appProject, pipeline, }...) } diff --git a/internal/cli/task_inspect.go b/internal/cli/task_inspect.go index 89ee65b0796..786fac85e8f 100644 --- a/internal/cli/task_inspect.go +++ b/internal/cli/task_inspect.go @@ -103,7 +103,9 @@ func (c *TaskInspectCommand) Run(args []string) int { return 1 } - var workspace, project, application string + var workspace string + project := "deleted" + application := "deleted" if taskResp.TaskJob.Workspace != nil { workspace = taskResp.TaskJob.Workspace.Workspace } @@ -259,6 +261,16 @@ func (c *TaskInspectCommand) FormatJob(job *pb.Job) error { errMsg = job.Error.Message } + var workspace string + project := "deleted" + application := "deleted" + if job.Workspace != nil { + workspace = job.Workspace.Workspace + } + if job.Application != nil { + project = job.Application.Project + application = job.Application.Application + } c.ui.Output("Job Configuration:", terminal.WithInfoStyle()) c.ui.NamedValues([]terminal.NamedValue{ { @@ -274,13 +286,13 @@ func (c *TaskInspectCommand) FormatJob(job *pb.Job) error { Name: "Target Runner", Value: targetRunner, }, { - Name: "Workspace", Value: job.Workspace.Workspace, + Name: "Workspace", Value: workspace, }, { - Name: "Project", Value: job.Application.Project, + Name: "Project", Value: project, }, { - Name: "Application", Value: job.Application.Application, + Name: "Application", Value: application, }, }, terminal.WithInfoStyle()) From 5ecb2b22b96709c3a96eaf54cbdb06eff593f4aa Mon Sep 17 00:00:00 2001 From: catsby Date: Thu, 3 Aug 2023 15:45:30 -0500 Subject: [PATCH 2/2] changelog for 4867 --- .changelog/4867.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/4867.txt diff --git a/.changelog/4867.txt b/.changelog/4867.txt new file mode 100644 index 00000000000..6e096b1116d --- /dev/null +++ b/.changelog/4867.txt @@ -0,0 +1,3 @@ +```release-note:bug +cli: Fix possible issues with deleted applications or projects failing to render in output +```