Skip to content

Commit

Permalink
use colored warnings and provide doc links where helpful
Browse files Browse the repository at this point in the history
  • Loading branch information
imLew authored and tmbo committed Jan 28, 2020
1 parent 62e033d commit d82d7e8
Show file tree
Hide file tree
Showing 58 changed files with 525 additions and 477 deletions.
3 changes: 3 additions & 0 deletions changelog/4780.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Colored warning messages. All warnings are now a bit easier to find since they are
yellow. Where it makes sense, we also added links to the documentation to help you
fix the warning.
2 changes: 1 addition & 1 deletion data/test_domains/default_with_slots_and_no_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ slots:
name:
type: text

templates:
responses:
utter_greet:
- text: "hey there {name}!" # {name} will be filled by slot (same name) or by custom action
utter_channel:
Expand Down
14 changes: 8 additions & 6 deletions rasa/cli/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os
import warnings
import sys
import json
from typing import Any, Optional, Text, List, Dict, TYPE_CHECKING
import logging
import os
import sys
from typing import Any, Dict, List, Optional, TYPE_CHECKING, Text

if TYPE_CHECKING:
from questionary import Question
Expand Down Expand Up @@ -42,8 +41,11 @@ def get_validated_path(
if current is None:
reason_str = f"Parameter '{parameter}' not set."
else:
warnings.warn(
f"'{current}' does not exist. Using default value '{default}' instead."
from rasa.utils.common import raise_warning # avoid import cycle

raise_warning(
f"The path '{current}' does not seem to exist. Using the "
f"default value '{default}' instead."
)

logger.debug(f"{reason_str} Using default location '{default}' instead.")
Expand Down
2 changes: 1 addition & 1 deletion rasa/core/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def combine_user_with_default_actions(user_actions: List[Text]) -> List[Text]:
def combine_with_templates(
actions: List[Text], templates: Dict[Text, Any]
) -> List[Text]:
"""Combines actions with utter actions listed in templates section"""
"""Combines actions with utter actions listed in responses section."""
unique_template_names = [a for a in list(templates.keys()) if a not in actions]
return actions + unique_template_names

Expand Down
20 changes: 10 additions & 10 deletions rasa/core/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
get_model,
)
from rasa.nlu.utils import is_url
from rasa.utils.common import update_sanic_log_level
from rasa.utils.common import raise_warning, update_sanic_log_level
from rasa.utils.endpoints import EndpointConfig

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -273,7 +273,7 @@ async def load_agent(
)

else:
warnings.warn("No valid configuration given to load agent.")
raise_warning("No valid configuration given to load agent.")
return None

except Exception as e:
Expand Down Expand Up @@ -463,7 +463,7 @@ async def handle_message(
"""Handle a single message."""

if not isinstance(message, UserMessage):
warnings.warn(
raise_warning(
"Passing a text to `agent.handle_message(...)` is "
"deprecated. Rather use `agent.handle_text(...)`.",
DeprecationWarning,
Expand Down Expand Up @@ -593,8 +593,8 @@ def toggle_memoization(self, activate: bool) -> None:
def continue_training(
self, trackers: List[DialogueStateTracker], **kwargs: Any
) -> None:
warnings.warn(
"Continue training will be removed in the next release. It won't be "
raise_warning(
"Continue training will be removed in the 2.0 release. It won't be "
"possible to continue the training, you should probably retrain instead.",
FutureWarning,
)
Expand Down Expand Up @@ -651,7 +651,7 @@ async def load_data(
unique_last_num_states = max_history
elif unique_last_num_states < max_history:
# possibility of data loss
warnings.warn(
raise_warning(
f"unique_last_num_states={unique_last_num_states} but "
f"maximum max_history={max_history}. "
f"Possibility of data loss. "
Expand Down Expand Up @@ -733,7 +733,7 @@ def handle_channels(

from rasa.core import run

warnings.warn(
raise_warning(
"Using `handle_channels` is deprecated. "
"Please use `rasa.run(...)` or see "
"`rasa.core.run.configure_app(...)` if you want to implement "
Expand Down Expand Up @@ -798,9 +798,9 @@ def persist(self, model_path: Text, dump_flattened_stories: bool = False) -> Non
"""Persists this agent into a directory for later loading and usage."""

if dump_flattened_stories:
warnings.warn(
raise_warning(
"The `dump_flattened_stories` argument will be removed from "
"`Agent.persist` in the next release. Please dump your "
"`Agent.persist` in the 2.0 release. Please dump your "
"training data separately if you need it to be part of the model.",
FutureWarning,
)
Expand Down Expand Up @@ -943,7 +943,7 @@ def load_local_model(
model_archive = get_latest_model(model_path)

if model_archive is None:
warnings.warn(f"Could not load local model in '{model_path}'.")
raise_warning(f"Could not load local model in '{model_path}'.")
return Agent()

working_directory = tempfile.mkdtemp()
Expand Down
5 changes: 4 additions & 1 deletion rasa/core/brokers/event_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@


# noinspection PyAbstractClass
from rasa.utils.common import raise_warning


class EventChannel(EventBroker):
warnings.warn(
raise_warning(
"The `EventChannel` class is deprecated, please inherit from "
"`EventBroker` instead. `EventChannel` will be removed "
"in future Rasa versions.",
Expand Down
7 changes: 4 additions & 3 deletions rasa/core/brokers/file_producer.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import warnings

from rasa.core.brokers.file import FileEventBroker
from rasa.utils.common import raise_warning


class FileProducer(FileEventBroker):
warnings.warn(
raise_warning(
"The `FileProducer` class is deprecated, please inherit from "
"`FileEventBroker` instead. `FileProducer` will be removed in "
"future Rasa versions.",
DeprecationWarning,
stacklevel=2,
FutureWarning,
docs="/api/event-brokers/",
)
4 changes: 2 additions & 2 deletions rasa/core/brokers/kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Optional

from rasa.core.brokers.broker import EventBroker
from rasa.utils.common import raise_warning
from rasa.utils.io import DEFAULT_ENCODING

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -93,12 +94,11 @@ def __init__(
security_protocol="SASL_PLAINTEXT",
loglevel=logging.ERROR,
) -> None:
warnings.warn(
raise_warning(
"The `KafkaProducer` class is deprecated, please inherit "
"from `KafkaEventBroker` instead. `KafkaProducer` will be "
"removed in future Rasa versions.",
DeprecationWarning,
stacklevel=2,
)

super(KafkaProducer, self).__init__(
Expand Down
14 changes: 6 additions & 8 deletions rasa/core/brokers/pika.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import json
import logging
import typing
import os
import warnings
import time
import typing
from collections import deque
from threading import Thread
from typing import Dict, Optional, Text, Union, Deque, Callable

import time
from typing import Callable, Deque, Dict, Optional, Text, Union

from rasa.constants import ENV_LOG_LEVEL_LIBRARIES, DEFAULT_LOG_LEVEL_LIBRARIES
from rasa.constants import DEFAULT_LOG_LEVEL_LIBRARIES, ENV_LOG_LEVEL_LIBRARIES
from rasa.core.brokers.broker import EventBroker
from rasa.utils.common import raise_warning
from rasa.utils.endpoints import EndpointConfig
from rasa.utils.io import DEFAULT_ENCODING

Expand Down Expand Up @@ -419,12 +418,11 @@ def __init__(
ENV_LOG_LEVEL_LIBRARIES, DEFAULT_LOG_LEVEL_LIBRARIES
),
):
warnings.warn(
raise_warning(
"The `PikaProducer` class is deprecated, please inherit "
"from `PikaEventBroker` instead. `PikaProducer` will be "
"removed in future Rasa versions.",
DeprecationWarning,
stacklevel=2,
)
super(PikaProducer, self).__init__(
host, username, password, port, queue, loglevel
Expand Down
7 changes: 3 additions & 4 deletions rasa/core/brokers/sql.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import contextlib
import json
import logging
import warnings
from typing import Any, Dict, Optional, Text

from rasa.core.brokers.broker import EventBroker
from rasa.utils.common import raise_warning
from rasa.utils.endpoints import EndpointConfig
import contextlib

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -85,11 +85,10 @@ def __init__(
username: Optional[Text] = None,
password: Optional[Text] = None,
):
warnings.warn(
raise_warning(
"The `SQLProducer` class is deprecated, please inherit "
"from `SQLEventBroker` instead. `SQLProducer` will be "
"removed in future Rasa versions.",
DeprecationWarning,
stacklevel=2,
)
super(SQLProducer, self).__init__(dialect, host, port, db, username, password)
3 changes: 2 additions & 1 deletion rasa/core/channels/facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from fbmessenger.attachments import Image
from fbmessenger.elements import Text as FBText
from fbmessenger.quick_replies import QuickReplies, QuickReply
from rasa.utils.common import raise_warning
from sanic import Blueprint, response
from sanic.request import Request
from typing import Text, List, Dict, Any, Callable, Awaitable, Iterable, Optional
Expand Down Expand Up @@ -169,7 +170,7 @@ async def send_text_with_buttons(

# buttons is a list of tuples: [(option_name,payload)]
if len(buttons) > 3:
warnings.warn(
raise_warning(
"Facebook API currently allows only up to 3 buttons. "
"If you add more, all will be ignored."
)
Expand Down
13 changes: 6 additions & 7 deletions rasa/core/channels/slack.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import json
import warnings
import logging
import re
from typing import Any, Awaitable, Callable, Dict, List, Optional, Text

from rasa.core.channels.channel import InputChannel, OutputChannel, UserMessage
from rasa.utils.common import raise_warning
from sanic import Blueprint, response
from sanic.request import Request
from sanic.response import HTTPResponse
from slackclient import SlackClient
from typing import Text, Optional, List, Dict, Any, Callable, Awaitable

from rasa.core.channels.channel import InputChannel
from rasa.core.channels.channel import UserMessage, OutputChannel

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -80,9 +79,9 @@ async def send_text_with_buttons(
text_block = {"type": "section", "text": {"type": "plain_text", "text": text}}

if len(buttons) > 5:
warnings.warn(
raise_warning(
"Slack API currently allows only up to 5 buttons. "
"If you add more, all will be ignored."
"Since you added more than 5, slack will ignore all of them."
)
return await self.send_text_message(recipient, text, **kwargs)

Expand Down
13 changes: 6 additions & 7 deletions rasa/core/channels/socketio.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import logging
import warnings
import uuid
from typing import Any, Awaitable, Callable, Dict, Iterable, List, Optional, Text

from rasa.core.channels.channel import InputChannel, OutputChannel, UserMessage
from rasa.utils.common import raise_warning
from sanic import Blueprint, response
from sanic.request import Request
from sanic.response import HTTPResponse
from socketio import AsyncServer
from typing import Optional, Text, Any, List, Dict, Iterable, Callable, Awaitable

from rasa.core.channels.channel import InputChannel
from rasa.core.channels.channel import UserMessage, OutputChannel

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -176,8 +175,8 @@ async def handle_message(sid: Text, data: Dict) -> Any:

if self.session_persistence:
if not data.get("session_id"):
warnings.warn(
"A message without a valid sender_id "
raise_warning(
"A message without a valid session_id "
"was received. This message will be "
"ignored. Make sure to set a proper "
"session id using the "
Expand Down
Loading

0 comments on commit d82d7e8

Please sign in to comment.