{"record":{"id":"a8c4a1e252d0386b","repo":"goharbor/harbor","slug":"port-number-in-metrics-is-not-valid","errorCode":null,"errorMessage":"Port number in metrics is not valid","messagePattern":"Port number in metrics is not valid","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"make/photon/prepare/models.py","lineNumber":136,"sourceCode":"                file.chmod(0o600)\n            elif file.name.endswith('.crt'):\n                file.chmod(0o644)\n\n            if file.name in self.db_certs_filename:\n                os.chown(file, PG_UID, PG_GID)\n            else:\n                os.chown(file, DEFAULT_UID, DEFAULT_GID)\n\n\nclass Metric:\n    def __init__(self, enabled: bool = False, port: int = 8080, path: str = \"metrics\"):\n        self.enabled = enabled\n        self.port = port\n        self.path = path\n\n    def validate(self):\n        if not port_number_valid(self.port):\n            raise Exception('Port number in metrics is not valid')\n\n\nclass JaegerExporter:\n    def __init__(self, config: dict):\n        if not config:\n            self.enabled = False\n            return\n        self.enabled = True\n        self.endpoint = config.get('endpoint')\n        self.username = config.get('username')\n        self.password = config.get('password')\n        self.agent_host = config.get('agent_host')\n        self.agent_port = config.get('agent_port')\n\n    def validate(self):\n        if not self.endpoint and not self.agent_host:\n            raise Exception('Jaeger Colector Endpoint or Agent host not set, must set one')\n        if self.endpoint and self.agent_host:","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/goharbor/harbor/blob/7b2fd08cc568955cca339afeefab27372840d936/make/photon/prepare/models.py#L118-L154","documentation":"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).","triggerScenarios":"client.SubmitScan(nil); or SubmitScan(req) where req stayed nil because a json.Unmarshal / FromJSON error was ignored earlier in the handler.","commonSituations":"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.","solutions":["Build the ScanRequest, run req.Validate(), and only then call SubmitScan","nil-check the request at the call site with a descriptive error naming the caller","When req originates from JSON, propagate FromJSON errors instead of continuing with a nil pointer"],"exampleFix":"// before\nresp, err := c.SubmitScan(req) // req could be nil\n\n// after\nif req == nil {\n    return nil, errors.New(\"scan request not initialized\")\n}\nif err := req.Validate(); err != nil {\n    return nil, err\n}\nresp, err := c.SubmitScan(req)","handlingStrategy":"validation","validationCode":"if req == nil {\n    return nil, errors.New(\"scan request not initialized\")\n}\nif err := req.Validate(); err != nil {\n    return nil, err\n}\nreturn c.SubmitScan(req)","typeGuard":null,"tryCatchPattern":"resp, err := c.SubmitScan(req)\nif err != nil {\n    if strings.Contains(err.Error(), \"nil request\") {\n        return nil, errors.New(\"scan request was never built; check upstream construction\")\n    }\n    return nil, err\n}","preventionTips":["Always run ScanRequest.Validate before SubmitScan","Propagate unmarshal errors instead of continuing with a nil pointer","Construct the request in exactly one place to avoid conditional-skip bugs"],"tags":["go","harbor","scan","rest-client","validation"],"backgroundTag":null,"analyzedSha":"7b2fd08cc568955cca339afeefab27372840d936","analyzedAt":"2026-08-16T00:00:10.961Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}