ssh kitten: Suppress error prints about invalid items in kitty.conf

Fixes #4985
This commit is contained in:
Kovid Goyal 2022-04-29 20:39:32 +05:30
parent 92c3af6a92
commit 4a7125ec92
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 20 additions and 6 deletions

View File

@ -39,7 +39,7 @@ from kitty.shm import SharedMemory
from kitty.types import run_once
from kitty.utils import (
SSHConnectionData, expandvars, resolve_abs_or_config_path,
set_echo as turn_off_echo
set_echo as turn_off_echo, suppress_error_logging
)
from .completion import complete, ssh_options
@ -152,7 +152,8 @@ def serialize_env(literal_env: Dict[str, str], env: Dict[str, str], base_env: Di
@run_once
def kitty_opts() -> Options:
from kitty.cli import create_default_opts
return create_default_opts()
with suppress_error_logging():
return create_default_opts()
def make_tarfile(ssh_opts: SSHOptions, base_env: Dict[str, str], compression: str = 'gz', literal_env: Dict[str, str] = {}) -> bytes:

View File

@ -13,8 +13,8 @@ from contextlib import contextmanager, suppress
from functools import lru_cache
from time import monotonic
from typing import (
TYPE_CHECKING, Any, Callable, Dict, Generator, Iterable, List, Mapping,
Match, NamedTuple, Optional, Pattern, Tuple, Union, cast
TYPE_CHECKING, Any, Callable, Dict, Generator, Iterable, Iterator, List,
Mapping, Match, NamedTuple, Optional, Pattern, Tuple, Union, cast
)
from .constants import (
@ -122,6 +122,19 @@ def log_error(*a: Any, **k: str) -> None:
output(msg)
@contextmanager
def suppress_error_logging() -> Iterator[None]:
before = getattr(log_error, 'redirect', suppress_error_logging)
setattr(log_error, 'redirect', lambda *a: None)
try:
yield
finally:
if before is suppress_error_logging:
delattr(log_error, 'redirect')
else:
setattr(log_error, 'redirect', before)
def ceil_int(x: float) -> int:
return int(math.ceil(x))
@ -536,7 +549,7 @@ def set_echo(fd: int = -1, on: bool = False) -> Tuple[int, List[Union[int, List[
@contextmanager
def no_echo(fd: int = -1) -> Generator[None, None, None]:
def no_echo(fd: int = -1) -> Iterator[None]:
import termios
fd, old = set_echo(fd)
try:
@ -954,7 +967,7 @@ def path_from_osc7_url(url: str) -> str:
if url.startswith('kitty-shell-cwd://'):
return '/' + url.split('/', 3)[-1]
if url.startswith('file://'):
from urllib.parse import urlparse, unquote
from urllib.parse import unquote, urlparse
return unquote(urlparse(url).path)
return ''