Skip to content

Commit

Permalink
chore(weave): tidy errors (#3785)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtruong authored Feb 28, 2025
1 parent e8e1e98 commit 2caadfe
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 45 deletions.
7 changes: 3 additions & 4 deletions tests/trace/test_op_decorator_behaviour.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import pytest

import weave
from weave.trace import errors
from weave.trace.op import is_op, op
from weave.trace.op import OpCallError, is_op, op
from weave.trace.refs import ObjectRef, parse_uri
from weave.trace.vals import MissingSelfInstanceError
from weave.trace.weave_client import Call
Expand Down Expand Up @@ -140,7 +139,7 @@ def test_sync_method_call(client, weave_obj, py_obj):
with pytest.raises(MissingSelfInstanceError):
weave_obj_method2 = weave_obj_method_ref.get()

with pytest.raises(errors.OpCallError):
with pytest.raises(OpCallError):
res2, call2 = py_obj.method.call(1)


Expand Down Expand Up @@ -175,7 +174,7 @@ async def test_async_method_call(client, weave_obj, py_obj):
with pytest.raises(MissingSelfInstanceError):
weave_obj_amethod2 = weave_obj_amethod_ref.get()

with pytest.raises(errors.OpCallError):
with pytest.raises(OpCallError):
res2, call2 = await py_obj.amethod.call(1)


Expand Down
3 changes: 1 addition & 2 deletions weave/flow/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
)
from weave.flow.util import make_memorable_name, transpose
from weave.trace.env import get_weave_parallelism
from weave.trace.errors import OpCallError
from weave.trace.objectify import register_object
from weave.trace.op import CallDisplayNameFunc, Op, as_op, is_op
from weave.trace.op import CallDisplayNameFunc, Op, OpCallError, as_op, is_op
from weave.trace.vals import WeaveObject
from weave.trace.weave_client import Call, get_ref

Expand Down
3 changes: 1 addition & 2 deletions weave/flow/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
from rich import print

from weave.flow.obj import Object
from weave.trace.errors import OpCallError
from weave.trace.isinstance import weave_isinstance
from weave.trace.op import Op, as_op, is_op
from weave.trace.op import Op, OpCallError, as_op, is_op
from weave.trace.op_caller import async_call_op
from weave.trace.weave_client import Call

Expand Down
5 changes: 2 additions & 3 deletions weave/flow/scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

import weave
from weave.flow.obj import Object
from weave.trace.errors import OpCallError
from weave.trace.isinstance import weave_isinstance
from weave.trace.op import Op, as_op, is_op
from weave.trace.op import Op, OpCallError, as_op, is_op
from weave.trace.op_caller import async_call_op
from weave.trace.weave_client import Call, sanitize_object_name

Expand Down Expand Up @@ -354,7 +353,7 @@ async def apply_scorer_async(
scorer argument names: {score_arg_names}
dataset keys: {example.keys()}
scorer.column_map: {getattr(scorer, 'column_map', '{}')}
scorer.column_map: {getattr(scorer, "column_map", "{}")}
Options for resolving:
a. if using the `Scorer` weave class, you can set the `scorer.column_map` attribute to map scorer argument names to dataset column names or
Expand Down
5 changes: 3 additions & 2 deletions weave/trace/context/weave_client_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import threading
from typing import TYPE_CHECKING

from weave.trace.errors import WeaveInitError

if TYPE_CHECKING:
from weave.trace.weave_client import WeaveClient

Expand Down Expand Up @@ -38,6 +36,9 @@ def get_weave_client() -> WeaveClient | None:
return _global_weave_client


class WeaveInitError(Exception): ...


def require_weave_client() -> WeaveClient:
if (client := get_weave_client()) is None:
raise WeaveInitError("You must call `weave.init(<project_name>)` first")
Expand Down
28 changes: 0 additions & 28 deletions weave/trace/errors.py

This file was deleted.

4 changes: 3 additions & 1 deletion weave/trace/op.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
tracing_disabled,
)
from weave.trace.context.tests_context import get_raise_on_captured_errors
from weave.trace.errors import OpCallError
from weave.trace.refs import ObjectRef
from weave.trace.util import log_once

Expand Down Expand Up @@ -216,6 +215,9 @@ def _is_unbound_method(func: Callable) -> bool:
return bool(is_method)


class OpCallError(Exception): ...


def _default_on_input_handler(func: Op, args: tuple, kwargs: dict) -> ProcessedInputs:
try:
sig = inspect.signature(func)
Expand Down
4 changes: 3 additions & 1 deletion weave/trace/vals.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from weave.trace import box
from weave.trace.context.tests_context import get_raise_on_captured_errors
from weave.trace.context.weave_client_context import get_weave_client
from weave.trace.errors import InternalError
from weave.trace.object_record import ObjectRecord
from weave.trace.op import is_op, maybe_bind_method
from weave.trace.refs import (
Expand Down Expand Up @@ -613,6 +612,9 @@ def __eq__(self, other: Any) -> bool:
return True


class InternalError(Exception): ...


def make_trace_obj(
val: Any,
new_ref: Optional[RefWithExtra], # Can this actually be None?
Expand Down
7 changes: 5 additions & 2 deletions weave/trace/weave_init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from weave.trace import autopatch, errors, init_message, trace_sentry, weave_client
from weave.trace import autopatch, init_message, trace_sentry, weave_client
from weave.trace.context import weave_client_context as weave_client_context
from weave.trace.settings import should_redact_pii, use_server_cache
from weave.trace_server import sqlite_trace_server
Expand Down Expand Up @@ -33,6 +33,9 @@ def get_username() -> str | None:
return None


class WeaveWandbAuthenticationException(Exception): ...


def get_entity_project_from_project_name(project_name: str) -> tuple[str, str]:
from weave.wandb_interface import wandb_api

Expand All @@ -41,7 +44,7 @@ def get_entity_project_from_project_name(project_name: str) -> tuple[str, str]:
api = wandb_api.get_wandb_api_sync()
entity_name = api.default_entity_name()
if entity_name is None:
raise errors.WeaveWandbAuthenticationException(
raise WeaveWandbAuthenticationException(
'weave init requires wandb. Run "wandb login"'
)
project_name = fields[0]
Expand Down

0 comments on commit 2caadfe

Please sign in to comment.