from typing import Union
from pathlib import Path


def __get_str_from_file(filename: Union[str, Path], encoding: str) -> str:
    """Return the contents of the file as string."""
    try:
        with open(str(filename), mode='r', encoding=encoding) as f:
            return f.read()
    except (FileNotFoundError, PermissionError):
        return '[el]#moca_error#'