{"record":{"id":"6fbb0199052e4dc9","repo":"nicolargo/glances","slug":"cannot-get-item-unit-for-plugin-plugin-str-e","errorCode":null,"errorMessage":"Cannot get {item} unit for plugin {plugin} ({str(e)})","messagePattern":"Cannot get (.+?) unit for plugin (.+?) \\((.+?)\\)","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"warning","filePath":"glances/outputs/glances_restful_api.py","lineNumber":1258,"sourceCode":"            )\n        else:\n            return GlancesJSONResponse(ret)\n\n    def _api_item_unit(self, plugin: str, item: str):\n        \"\"\"Glances API RESTful implementation.\n\n        Return the JSON representation of the couple plugin/item unit\n        HTTP/200 if OK\n        HTTP/400 if plugin is not found\n        HTTP/404 if others error\n        \"\"\"\n        self._check_if_plugin_available(plugin)\n\n        try:\n            # Get the unit\n            ret = self.stats.get_plugin(plugin).get_item_info(item, 'unit')\n        except Exception as e:\n            raise HTTPException(status.HTTP_404_NOT_FOUND, f\"Cannot get {item} unit for plugin {plugin} ({str(e)})\")\n        else:\n            return GlancesJSONResponse(ret)\n\n    def _api_value(self, plugin: str, item: str, value: str | int | float):\n        \"\"\"Glances API RESTful implementation.\n\n        Return the process stats (dict) for the given item=value\n        HTTP/200 if OK\n        HTTP/400 if plugin is not found\n        HTTP/404 if others error\n        \"\"\"\n        self._check_if_plugin_available(plugin)\n\n        # Update the stat\n        self.__update_stats(get_plugin_dependencies(plugin))\n\n        try:\n            # Get the RAW value","sourceCodeStart":1240,"sourceCodeEnd":1276,"githubUrl":"https://github.com/nicolargo/glances/blob/a240d8dfb3105a38b5964357ec21768594b0e83e/glances/outputs/glances_restful_api.py#L1240-L1276","documentation":"Raised when get_item_info(item, 'unit') fails on the item-unit endpoint, returned as HTTP 404. Same metadata source as descriptions: the item must exist in the plugin's items description dict with a unit entry.","triggerScenarios":"GET /api/4/<plugin>/<item>/unit for an item with no unit defined or not present in item metadata — e.g., counters or newly added fields.","commonSituations":"Clients auto-labeling units for every stat key; many items legitimately have no unit.","solutions":["Treat 404 as 'unitless' in client logic","Check known items via /api/4/<plugin>/views","Align with the deployed glances version's metadata"],"exampleFix":"# before\nunit = fetch(f'/api/4/mem/{item}/unit').json()  # 404 for unitless items\n# after\nr = fetch(f'/api/4/mem/{item}/unit')\nunit = r.json() if r.ok else ''","handlingStrategy":"fallback","validationCode":"views = httpx.get(f'{BASE}/api/4/{plugin}/views').json()\nhas_unit = item in views","typeGuard":"def has_unit(item: str, views: dict) -> bool:\n    return item in views","tryCatchPattern":"r = httpx.get(f'{BASE}/api/4/{plugin}/{item}/unit')\nunit = r.json() if r.status_code == 200 else ''  # unitless fallback","preventionTips":["Treat missing units as unitless rather than an error"],"tags":["glances","rest-api","http-404","unit","metadata"],"backgroundTag":"http-404-resource-not-found","analyzedSha":"a240d8dfb3105a38b5964357ec21768594b0e83e","analyzedAt":"2026-08-27T19:15:19.178Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}