Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: raise ValueError instead of exception #139

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ def is_metrics_in_custom_query(query: GAQL) -> bool:
return False

def check_connection(self, logger: logging.Logger, config: Mapping[str, Any]) -> Tuple[bool, any]:
config = self._validate_and_transform(config)
try:
config = self._validate_and_transform(config)
except ValueError as e:
return False, f"error while validating custom query: {repr(e)}"
except Exception as e:
return False, f"error: {repr(e)}"
try:
logger.info("Checking the config")
google_api = GoogleAds(credentials=self.get_credentials(config))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class GAQL:
def parse(cls, query):
m = cls.REGEX.match(query)
if not m:
raise Exception(f"incorrect GAQL query statement: {repr(query)}")
raise ValueError(f"incorrect GAQL query statement: {repr(query)}")

fields = [f.strip() for f in m.group("FieldNames").split(",")]
for field in fields:
if not cls.REGEX_FIELD_NAME.match(field):
raise Exception(f"incorrect GAQL query statement: {repr(query)}")
raise ValueError(f"incorrect GAQL query statement: {repr(query)}")

resource_name = m.group("ResourceName")
where = cls._normalize(m.group("WhereClause") or "")
Expand Down
Loading