googleapis/mcp-toolbox · error
failed to list data scan jobs for scan %q
Error message
failed to list data scan jobs for scan %q
What it means
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.
Source
Thrown at internal/sources/dataplex/dataplex.go:952
// If jobID is provided, fetch that specific job directly!
if jobID != "" {
name := fmt.Sprintf("projects/%s/locations/%s/dataScans/%s/jobs/%s", s.ProjectID(), location, scanID, jobID)
req := &dataplexpb.GetDataScanJobRequest{
Name: name,
}
return s.DataScanClient.GetDataScanJob(ctx, req)
}
// Fallback to listing and returning the latest job (PageSize: 1)
parent := fmt.Sprintf("projects/%s/locations/%s/dataScans/%s", s.ProjectID(), location, scanID)
req := &dataplexpb.ListDataScanJobsRequest{
Parent: parent,
PageSize: 1,
}
it := s.DataScanClient.ListDataScanJobs(ctx, req)
if it == nil {
return nil, fmt.Errorf("failed to list data scan jobs for scan %q", scanID)
}
job, err := it.Next()
if err == iterator.Done {
return nil, nil
}
if err != nil {
return nil, err
}
return job, nil
}
func (s *Source) GenerateDataProfile(ctx context.Context, location, resourcePath string, publish bool) (string, error) {
parent := fmt.Sprintf("projects/%s/locations/%s", s.ProjectID(), location)
dataScanID := fmt.Sprintf("nq-prof-%s", uuid.New().String())
req := &dataplexpb.CreateDataScanRequest{View on GitHub (pinned to 8cc6e09de2)
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
Example fix
// before
it := s.DataScanClient.ListDataScanJobs(ctx, req)
if it == nil { ... }
// after
if s.DataScanClient == nil {
return nil, errors.New("dataplex scan client not initialized")
}
it := s.DataScanClient.ListDataScanJobs(ctx, req) Defensive patterns
Strategy: validation
Validate before calling
if src == nil || src.DataScanClient == nil { return errors.New("dataplex scan client not initialized") }
if scanID == "" { return errors.New("scanID required") } Type guard
if client, ok := src.DataScanClient.(*dataplexpb.DataScanClient); !ok || client == nil { ... } Try / catch
job, err := src.GetJobStatus(ctx, loc, scan, job)
if err != nil {
if strings.Contains(err.Error(), "failed to list data scan jobs") {
// check API enablement and re-init source
}
return err
} Prevention
- Enable dataplex.googleapis.com before initializing the source
- Assert client non-nil right after source construction
- Avoid mocks returning nil iterators in integration tests
When it happens
Trigger: Calling GetJobStatus for a scan when s.DataScanClient is partially initialized or its ListDataScanJobs returns nil (bad client construction, dependency injection with a stub).
Common situations: 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.
Related errors
- failed to initialize dataplex client: %w
- failed to create Dataplex client for project %q: %w
- failed to get dataplex client: %w
- unable to create client: %w
- failed to get project details for project %q: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/2ce5c297d27666c4.
Report an issue: GitHub.