{"record":{"id":"3e449f3d0b02eb7b","repo":"Lightning-AI/pytorch-lightning","slug":"the-filename-cannot-be-empty","errorCode":null,"errorMessage":"The filename cannot be empty","messagePattern":"The filename cannot be empty","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/callbacks/on_exception_checkpoint.py","lineNumber":55,"sourceCode":"\n    Raises:\n        ValueError:\n            If ``filename`` is empty.\n\n\n    Example:\n        >>> from lightning.pytorch import Trainer\n        >>> from lightning.pytorch.callbacks import OnExceptionCheckpoint\n        >>> trainer = Trainer(callbacks=[OnExceptionCheckpoint(\".\")])\n\n    \"\"\"\n\n    FILE_EXTENSION = \".ckpt\"\n\n    def __init__(self, dirpath: _PATH, filename: str = \"on_exception\") -> None:\n        super().__init__()\n        if not filename:\n            raise ValueError(\"The filename cannot be empty\")\n        # not optional because an exception could occur at any moment, so we cannot wait until the `setup` hook\n        self.dirpath = dirpath\n        self.filename = filename\n\n    @property\n    def ckpt_path(self) -> str:\n        return os.path.join(self.dirpath, self.filename + self.FILE_EXTENSION)\n\n    @override\n    def on_exception(self, trainer: \"pl.Trainer\", *_: Any, **__: Any) -> None:\n        # overwrite if necessary\n        trainer.save_checkpoint(self.ckpt_path)\n\n    @override\n    def teardown(self, trainer: \"pl.Trainer\", *_: Any, **__: Any) -> None:\n        trainer.strategy.remove_checkpoint(self.ckpt_path)\n","sourceCodeStart":37,"sourceCodeEnd":72,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/callbacks/on_exception_checkpoint.py#L37-L72","documentation":"OnExceptionCheckpoint saves a checkpoint when an exception interrupts training. Its filename becomes part of the checkpoint path immediately at construction (since an exception can occur at any moment), so an empty filename is rejected with ValueError in __init__.","triggerScenarios":"Calling OnExceptionCheckpoint(dirpath=..., filename='') or filename=None (which fails the truthiness check); constructing it programmatically with a computed filename that ends up empty.","commonSituations":"Passing a filename variable that is empty due to a preceding bug or config omission; passing None expecting a default to kick in (the default is only used when the argument is omitted).","solutions":["Provide a non-empty filename string, e.g., filename='on_exception' (the default)","Omit the filename argument entirely to use the default 'on_exception'","Guard programmatically generated filenames with `filename = filename or 'on_exception'`"],"exampleFix":"# before\nOnExceptionCheckpoint(dirpath='ckpts', filename='')\n# after\nOnExceptionCheckpoint(dirpath='ckpts', filename='on_exception')","handlingStrategy":"validation","validationCode":"filename = filename or 'on_exception'\nassert filename, 'filename must be non-empty'","typeGuard":"def valid_filename(f) -> bool:\n    return isinstance(f, str) and len(f.strip()) > 0","tryCatchPattern":null,"preventionTips":["Don't pass filename=None expecting a default; omit the argument instead","Guard computed filenames with `or` fallback"],"tags":["pytorch-lightning","on-exception-checkpoint","filename","argument-validation"],"backgroundTag":"empty-required-string","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}