Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] function j_loader does not properly raise when input file non-existing and not with expected extension name #4490

Open
kirk0830 opened this issue Dec 23, 2024 · 0 comments
Labels

Comments

@kirk0830
Copy link

Bug summary

def j_loader(filename: Union[str, Path]) -> dict[str, Any]:
    """Load yaml or json settings file.

    Parameters
    ----------
    filename : Union[str, Path]
        path to file

    Returns
    -------
    dict[str, Any]
        loaded dictionary

    Raises
    ------
    TypeError
        if the supplied file is of unsupported type
    """
    filepath = Path(filename)
    if filepath.suffix.endswith("json"):
        with filepath.open() as fp:
            return json.load(fp)
    elif filepath.suffix.endswith(("yml", "yaml")):
        with filepath.open() as fp:
            return yaml.safe_load(fp)
    else:
        raise TypeError("config file must be json, or yaml/yml")

If the file is not found, it will raise TypeError, but this is not the expected behavior: in this case, should raise FileNotFoundError instead.

DeePMD-kit Version

devel

Backend and its version

any

How did you download the software?

Built from source

Input Files, Running Commands, Error Log, etc.

no

Steps to Reproduce

can be easily trigger the inappropriate raise if run deepmd-kit like

dp train SomeNonExistingFile.OtherThanJsonOrYaml

Further Information, Files, and Links

No response

@kirk0830 kirk0830 added the bug label Dec 23, 2024
@kirk0830 kirk0830 changed the title [BUG] function j_loader does not properly raises when input file non-existing [BUG] function j_loader does not properly raise when input file non-existing and not with expected extension name Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant