From 481f30f237efb55df2bdc6d6385e95736227bd07 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Thu, 31 Dec 2020 17:53:11 +0000 Subject: [PATCH] fix encoding --- CHANGELOG.md | 6 ++++++ pyproject.toml | 2 +- rich/default_styles.py | 1 + rich/traceback.py | 10 +++++++--- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ffa1e86..ed618f8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [9.6.1] - 2020-12-31 + +### Fixed + +- Fixed encoding error on Windows when loading code on Windows + ## [9.6.0] - 2020-12-30 ### Changed diff --git a/pyproject.toml b/pyproject.toml index cc75ef12..575a4d19 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ name = "rich" homepage = "https://github.com/willmcgugan/rich" documentation = "https://rich.readthedocs.io/en/latest/" -version = "9.6.0" +version = "9.6.1" description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal" authors = ["Will McGugan "] license = "MIT" diff --git a/rich/default_styles.py b/rich/default_styles.py index 28ca10fa..a192040e 100644 --- a/rich/default_styles.py +++ b/rich/default_styles.py @@ -99,6 +99,7 @@ DEFAULT_STYLES: Dict[str, Style] = { "table.cell": Style.null(), "table.title": Style(italic=True), "table.caption": Style(italic=True, dim=True), + "traceback.error": Style(dim=True, color="red", bold=True), "traceback.border.syntax_error": Style(color="bright_red"), "traceback.border": Style(color="red"), "traceback.text": Style.null(), diff --git a/rich/traceback.py b/rich/traceback.py index 45abbd62..985848b0 100644 --- a/rich/traceback.py +++ b/rich/traceback.py @@ -443,7 +443,9 @@ class Traceback: """ code = code_cache.get(filename) if code is None: - with open(filename, "rt") as code_file: + with open( + filename, "rt", encoding="utf-8", errors="replace" + ) as code_file: code = code_file.read() code_cache[filename] = code return code @@ -492,8 +494,10 @@ class Traceback: indent_guides=self.indent_guides, ) yield "" - except Exception: - pass + except Exception as error: + yield Text.assemble( + (f"{error.__class__.__name__}: {error}", "traceback.error"), + ) else: yield ( Columns(