Skip to content

Commit

Permalink
chore(weave): ruff: enable TRY400 (#2905)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtruong authored Nov 6, 2024
1 parent 4ca4115 commit 5ce195a
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions docs/scripts/generate_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def generate_screenshot_from_browser(
logging.info(f"Screenshot captured successfully: {output_path}")

except Exception as e:
logging.error(f"Error capturing screenshot for {url}: {str(e)}")
logging.exception(f"Error capturing screenshot for {url}: {str(e)}")
raise

finally:
Expand All @@ -114,15 +114,15 @@ def generate_screenshot(screenshot_spec):
)
)
except Exception as e:
logging.error(f"Failed to generate screenshot: {str(e)}")
logging.exception(f"Failed to generate screenshot: {str(e)}")


def generate_screenshots_from_spec(spec_filepath):
try:
with open(spec_filepath) as f:
spec = json.load(f)
except (FileNotFoundError, json.JSONDecodeError) as e:
logging.error(f"Error reading or parsing spec file: {str(e)}")
logging.exception(f"Error reading or parsing spec file: {str(e)}")
return

with ThreadPoolExecutor() as executor:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ select = [
"TRY002", # https://docs.astral.sh/ruff/rules/raise-vanilla-class/
"TRY004", # https://docs.astral.sh/ruff/rules/type-check-without-type-error/
"TRY300", # https://docs.astral.sh/ruff/rules/try-consider-else/
"TRY400", # https://docs.astral.sh/ruff/rules/error-instead-of-exception/
"C", # https://docs.astral.sh/ruff/rules/#convention-c
]
ignore = [
Expand Down
2 changes: 1 addition & 1 deletion weave/trace/concurrent/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def _execute_directly(
res = f(*args, **kwargs)
fut.set_result(res)
except Exception as e:
logger.error(f"Task failed: {_format_exception(e)}")
logger.exception(f"Task failed: {_format_exception(e)}")
fut.set_exception(e)
return fut

Expand Down
6 changes: 3 additions & 3 deletions weave/trace/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def attempt_patch(self) -> bool:
except Exception as e:
if get_raise_on_captured_errors():
raise
logger.error(f"Error patching - some logs may not be captured: {e}")
logger.exception(f"Error patching - some logs may not be captured: {e}")
all_successful = False
return all_successful

Expand All @@ -39,7 +39,7 @@ def undo_patch(self) -> bool:
except Exception as e:
if get_raise_on_captured_errors():
raise
logger.error(f"Error unpatching: {e}")
logger.exception(f"Error unpatching: {e}")
all_successful = False
return all_successful

Expand Down Expand Up @@ -89,7 +89,7 @@ def attempt_patch(self) -> bool:
try:
new_val = self._make_new_value(original_value)
except Exception:
logger.error(f"Failed to patch {self._attribute_name}")
logger.exception(f"Failed to patch {self._attribute_name}")
return False
setattr(
target.base_symbol,
Expand Down
2 changes: 1 addition & 1 deletion weave/trace_server/async_batch_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _process_batches(self) -> None:
# 413: payload too large, don't raise just log
if get_raise_on_captured_errors():
raise
logger.error(f"Error processing batch: {e}")
logger.exception(f"Error processing batch: {e}")
else:
raise e

Expand Down
8 changes: 4 additions & 4 deletions weave/trace_server/costs/insert_costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def load_costs_from_json(file_name: str = COST_FILE) -> dict[str, list[CostDetai
with open(file_path) as file:
data = json.load(file)
except json.JSONDecodeError as e:
logger.error("JSON decode error: %s", e)
logger.exception("JSON decode error: %s", e)
raise
return data

Expand Down Expand Up @@ -154,15 +154,15 @@ def insert_costs(client: Client, target_db: str) -> None:
try:
new_costs = load_costs_from_json()
except Exception as e:
logger.error("Failed to load costs from json, %s", e)
logger.exception("Failed to load costs from json, %s", e)
return
logger.info("Loaded %d costs from json", sum_costs(new_costs))

# filter out current costs
try:
new_costs = filter_out_current_costs(client, new_costs)
except Exception as e:
logger.error("Failed to filter out current costs, %s", e)
logger.exception("Failed to filter out current costs, %s", e)
return

logger.info(
Expand All @@ -177,7 +177,7 @@ def insert_costs(client: Client, target_db: str) -> None:
try:
insert_costs_into_db(client, new_costs)
except Exception as e:
logger.error("Failed to insert costs into db, %s", e)
logger.exception("Failed to insert costs into db, %s", e)
return
logger.info("Inserted %d costs", sum_costs(new_costs))

Expand Down
2 changes: 1 addition & 1 deletion weave/trace_server/model_providers/model_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def read_model_to_provider_info_map(
with open(full_path) as f:
return json.load(f)
except Exception as e:
logger.error(
logger.exception(
f"Failed to read model to provider info file at: {full_path}", exc_info=e
)
return {}
Expand Down

0 comments on commit 5ce195a

Please sign in to comment.