{"record":{"id":"2ce5c297d27666c4","repo":"googleapis/mcp-toolbox","slug":"failed-to-list-data-scan-jobs-for-scan-q","errorCode":null,"errorMessage":"failed to list data scan jobs for scan %q","messagePattern":"failed to list data scan jobs for scan %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/dataplex/dataplex.go","lineNumber":952,"sourceCode":"\t// If jobID is provided, fetch that specific job directly!\n\tif jobID != \"\" {\n\t\tname := fmt.Sprintf(\"projects/%s/locations/%s/dataScans/%s/jobs/%s\", s.ProjectID(), location, scanID, jobID)\n\t\treq := &dataplexpb.GetDataScanJobRequest{\n\t\t\tName: name,\n\t\t}\n\t\treturn s.DataScanClient.GetDataScanJob(ctx, req)\n\t}\n\n\t// Fallback to listing and returning the latest job (PageSize: 1)\n\tparent := fmt.Sprintf(\"projects/%s/locations/%s/dataScans/%s\", s.ProjectID(), location, scanID)\n\treq := &dataplexpb.ListDataScanJobsRequest{\n\t\tParent:   parent,\n\t\tPageSize: 1,\n\t}\n\n\tit := s.DataScanClient.ListDataScanJobs(ctx, req)\n\tif it == nil {\n\t\treturn nil, fmt.Errorf(\"failed to list data scan jobs for scan %q\", scanID)\n\t}\n\n\tjob, err := it.Next()\n\tif err == iterator.Done {\n\t\treturn nil, nil\n\t}\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn job, nil\n}\n\nfunc (s *Source) GenerateDataProfile(ctx context.Context, location, resourcePath string, publish bool) (string, error) {\n\tparent := fmt.Sprintf(\"projects/%s/locations/%s\", s.ProjectID(), location)\n\tdataScanID := fmt.Sprintf(\"nq-prof-%s\", uuid.New().String())\n\n\treq := &dataplexpb.CreateDataScanRequest{","sourceCodeStart":934,"sourceCodeEnd":970,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/dataplex/dataplex.go#L934-L970","documentation":"GetJobStatus lists data scan jobs with PageSize 1 to fetch the latest job for a scan. The googleapi iterator should never be nil from a valid client; if ListDataScanJobs returns nil (unconfigured client, failed lazy initialization, or a stub), the source returns this error rather than dereferencing a nil iterator. It signals the scan's ListDataScanJobs call could not even start.","triggerScenarios":"Calling GetJobStatus for a scan when s.DataScanClient is partially initialized or its ListDataScanJobs returns nil (bad client construction, dependency injection with a stub).","commonSituations":"Dataplex source initialized without full API enablement; scanning in a project where the DataScan API is disabled so the client factory returns nil; test mocks returning nil iterators.","solutions":["Verify the Dataplex API (dataplex.googleapis.com) is enabled on the project","Re-create the Dataplex source so DataScanClient initializes correctly","Check that the scanID/parent path is a valid existing DataScan","If using a mock, make ListDataScanJobs return a valid iterator"],"exampleFix":"// before\nit := s.DataScanClient.ListDataScanJobs(ctx, req)\nif it == nil { ... }\n// after\nif s.DataScanClient == nil {\n    return nil, errors.New(\"dataplex scan client not initialized\")\n}\nit := s.DataScanClient.ListDataScanJobs(ctx, req)","handlingStrategy":"validation","validationCode":"if src == nil || src.DataScanClient == nil { return errors.New(\"dataplex scan client not initialized\") }\nif scanID == \"\" { return errors.New(\"scanID required\") }","typeGuard":"if client, ok := src.DataScanClient.(*dataplexpb.DataScanClient); !ok || client == nil { ... }","tryCatchPattern":"job, err := src.GetJobStatus(ctx, loc, scan, job)\nif err != nil {\n\tif strings.Contains(err.Error(), \"failed to list data scan jobs\") {\n\t\t// check API enablement and re-init source\n\t}\n\treturn err\n}","preventionTips":["Enable dataplex.googleapis.com before initializing the source","Assert client non-nil right after source construction","Avoid mocks returning nil iterators in integration tests"],"tags":["dataplex","nil-iterator","client-init","gcp"],"backgroundTag":"nil-client-reference","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}