{"record":{"id":"298407830ba6c150","repo":"stamparm/maltrail","slug":"no-package-table-found-in-s","errorCode":null,"errorMessage":"[!] no [package] table found in %s","messagePattern":"\\[!\\] no \\[package\\] table found in (.+?)","errorType":"console","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"sensor/tools/check_version.py","lineNumber":53,"sourceCode":"def _read(path):\n    with open(path, \"r\") as f:\n        return f.read()\n\n\ndef settings_version():\n    \"\"\"VERSION = \"3.0\" from core/settings.py, without importing it (it has side effects).\"\"\"\n    match = re.search(r\"^VERSION\\s*=\\s*[\\\"']([^\\\"']+)[\\\"']\", _read(SETTINGS), re.M)\n    if not match:\n        raise SystemExit(\"[!] no VERSION assignment found in %s\" % SETTINGS)\n    return match.group(1)\n\n\ndef cargo_version():\n    \"\"\"version = \"3.0.0\" from the [package] table only - dependency versions must not match.\"\"\"\n    text = _read(CARGO)\n    package = re.search(r\"^\\[package\\]\\s*$(.*?)(?=^\\[|\\Z)\", text, re.M | re.S)\n    if not package:\n        raise SystemExit(\"[!] no [package] table found in %s\" % CARGO)\n    match = re.search(r\"^version\\s*=\\s*\\\"([^\\\"]+)\\\"\", package.group(1), re.M)\n    if not match:\n        raise SystemExit(\"[!] no version key in the [package] table of %s\" % CARGO)\n    return match.group(1)\n\n\ndef citation_version():\n    \"\"\"version: \"3.0\" from CITATION.cff.\n\n    Nothing linked this to the tree, and it drifted: the file still claimed 3.0 while the code,\n    the sensor and the published tag were all 3.1.1. That is not cosmetic - CITATION.cff exists\n    so a paper can cite a specific version, and it had been quietly citing the wrong one.\n    \"\"\"\n\n    match = re.search(r\"^version\\s*:\\s*[\\\"']([^\\\"']+)[\\\"']\", _read(CITATION), re.M)\n    if not match:\n        raise SystemExit(\"[!] no version key found in %s\" % CITATION)\n    return match.group(1)","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/stamparm/maltrail/blob/77cfb06d7606506d101bbcec0786c77166c4255e/sensor/tools/check_version.py#L35-L71","documentation":"cargo_version() in check_version.py parses Cargo.toml as text, isolating the [package] table with the regex ^\\[package\\]\\s*$(.*?)(?=^\\[|\\Z) so that dependency tables like [dependencies] never contribute a version. If no [package] table header exists in the file, it raises SystemExit with this message — the manifest lacks the mandatory package section Cargo itself requires.","triggerScenarios":"Cargo.toml does not contain a line starting with [package]: the file is empty, was truncated, is actually a different TOML file (wrong path in the CARGO constant), uses a workspace-root manifest that only holds [workspace], or the header is malformed (e.g. [ package ] with inner spaces on the same line pattern the regex doesn't match, or commented out).","commonSituations":"A workspace root Cargo.toml (virtual manifest) with only [workspace] is checked instead of the member crate's manifest; a bad merge dropped the [package] section; the file path constant became stale after restructuring the repo.","solutions":["Add a [package] section to Cargo.toml with name, version, and edition fields if the crate is a real package.","If Cargo.toml is a virtual workspace root, point the CARGO constant in check_version.py at a member crate's Cargo.toml that has [package].","Check git history (git log -p Cargo.toml) to find and restore a [package] section lost in a merge or edit.","Verify the [package] header is not commented out and starts the line exactly as [package]."],"exampleFix":"# before (Cargo.toml)\n[workspace]\nmembers = [\"sensor\"]\n# after\n[package]\nname = \"sensor\"\nversion = \"3.0.0\"\nedition = \"2021\"","handlingStrategy":"validation","validationCode":"import re\ntext = open(\"Cargo.toml\").read()\nassert re.search(r'^\\[package\\]\\s*$', text, re.M), \\\n    \"Cargo.toml must contain a [package] table before running check_version\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never delete the [package] section; for workspaces, keep per-crate manifests intact and check member manifests, not virtual workspace roots.","Run cargo verify-project or cargo metadata in CI before the version-consistency check to catch broken manifests early.","Review merges touching Cargo.toml carefully; a dropped [package] header fails both cargo and this checker.","Keep the CARGO path constant in check_version.py in sync with repo restructurings."],"tags":["cargo","toml","versioning","manifest"],"backgroundTag":"missing-required-config-field","analyzedSha":"77cfb06d7606506d101bbcec0786c77166c4255e","analyzedAt":"2026-09-13T03:50:16.010Z","contentChangedAt":"2026-09-13T03:50:16.010Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}