goharbor/harbor · error · Exception

Port number in metrics is not valid

Error message

Port number in metrics is not valid

What it means

SubmitScan on the v1 scanner-adapter REST client (src/pkg/scan/rest/v1/client.go) posts a scan request to the adapter's /scan endpoint. A nil *ScanRequest is rejected with 'nil request' before any HTTP traffic or marshalling occurs. Only pointer presence is checked here; field-level correctness is the caller's responsibility (see ScanRequest.Validate).

Source

Thrown at make/photon/prepare/models.py:136

                file.chmod(0o600)
            elif file.name.endswith('.crt'):
                file.chmod(0o644)

            if file.name in self.db_certs_filename:
                os.chown(file, PG_UID, PG_GID)
            else:
                os.chown(file, DEFAULT_UID, DEFAULT_GID)


class Metric:
    def __init__(self, enabled: bool = False, port: int = 8080, path: str = "metrics"):
        self.enabled = enabled
        self.port = port
        self.path = path

    def validate(self):
        if not port_number_valid(self.port):
            raise Exception('Port number in metrics is not valid')


class JaegerExporter:
    def __init__(self, config: dict):
        if not config:
            self.enabled = False
            return
        self.enabled = True
        self.endpoint = config.get('endpoint')
        self.username = config.get('username')
        self.password = config.get('password')
        self.agent_host = config.get('agent_host')
        self.agent_port = config.get('agent_port')

    def validate(self):
        if not self.endpoint and not self.agent_host:
            raise Exception('Jaeger Colector Endpoint or Agent host not set, must set one')
        if self.endpoint and self.agent_host:

View on GitHub (pinned to 7b2fd08cc5)

Solutions

  1. Build the ScanRequest, run req.Validate(), and only then call SubmitScan
  2. nil-check the request at the call site with a descriptive error naming the caller
  3. When req originates from JSON, propagate FromJSON errors instead of continuing with a nil pointer

Example fix

// before
resp, err := c.SubmitScan(req) // req could be nil

// after
if req == nil {
    return nil, errors.New("scan request not initialized")
}
if err := req.Validate(); err != nil {
    return nil, err
}
resp, err := c.SubmitScan(req)
Defensive patterns

Strategy: validation

Validate before calling

if req == nil {
    return nil, errors.New("scan request not initialized")
}
if err := req.Validate(); err != nil {
    return nil, err
}
return c.SubmitScan(req)

Try / catch

resp, err := c.SubmitScan(req)
if err != nil {
    if strings.Contains(err.Error(), "nil request") {
        return nil, errors.New("scan request was never built; check upstream construction")
    }
    return nil, err
}

Prevention

When it happens

Trigger: client.SubmitScan(nil); or SubmitScan(req) where req stayed nil because a json.Unmarshal / FromJSON error was ignored earlier in the handler.

Common situations: API handlers that build ScanRequest from a request body but discard unmarshal errors; conditional construction paths that skip building the request under some flag; refactors changing the function signature from value to pointer.

Related errors


AI-assisted analysis of goharbor/harbor@7b2fd08cc5 (2026-08-16). Data as JSON: /api/errors/a8c4a1e252d0386b. Report an issue: GitHub.