Skip to content

misleading error "Failed to load Noxfile noxfile.py, no such file exists." #566

@weatherfrog

Description

@weatherfrog

Describe the bug
If a FileNotFoundError occurs somewhere on module-level within noxfile.py, nox will display a misleading error:

misleading error "Failed to load Noxfile noxfile.py, no such file exists."

The problem is here: https://github.com/theacodes/nox/blob/main/nox/tasks.py#L109
This except clause is harmful. Something like this would solve the problem:

if not Path(global_config.noxfile).exists():
    logger.error(
        f"Failed to load Noxfile {global_config.noxfile}, no such file exists."
    )
    return 2

Shall I create a PR?

How to reproduce
noxfile.py:

from pathlib import Path

import nox

requirements = Path("/non-existing/path/requirements.txt").read_text()

@nox.session(python=["3.9"])
def foo(session):
    pass
$ nox -s foo
nox > Failed to load Noxfile [...]/noxfile.py, no such file exists.

Expected behavior

The stack trace of the actual error should be visible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions