44
55from google .cloud import bigquery
66
7- from dataform2looker .exceptions import UnsupportedDatabaseTypeError
7+ from dataform2looker .exceptions import (
8+ InvalidFieldTypeError ,
9+ TableNotFoundError ,
10+ UnsupportedDatabaseTypeError ,
11+ )
812
913
1014class Column :
@@ -48,6 +52,9 @@ def __init__(
4852 data_type: The original database data type of the column.
4953 time_frames: A list of timeframes for time dimension groups (optional).
5054
55+ Raises:
56+ InvalidFieldTypeError: If an unsupported field type is provided.
57+
5158 Sets the attributes and constructs the `column_dictionary` for Looker integration.
5259 If the column is a time dimension group, it adds `timeframes` and `datatype` to the dictionary.
5360 """ # noqa: E501
@@ -56,10 +63,11 @@ def __init__(
5663 self .field_type = field_type
5764 self .data_type = data_type
5865 self .time_frames = time_frames
59- assert (
60- self .field_type in self ._DIMENSION_TYPE_MAP
61- ), f"Invalid field type, use one of { self ._DIMENSION_TYPE_MAP .keys ()} ,\
62- got { self .field_type } "
66+ if self .field_type not in self ._DIMENSION_TYPE_MAP :
67+ raise InvalidFieldTypeError (
68+ field_type = self .field_type ,
69+ allowed_types = list (self ._DIMENSION_TYPE_MAP .keys ()),
70+ )
6371 self .dimension_type = self ._DIMENSION_TYPE_MAP [self .field_type ]
6472 self .column_dictionary = {
6573 "name" : self .name ,
@@ -224,11 +232,19 @@ def __get_columns(self) -> list[Column]:
224232 This method connects to BigQuery, fetches the schema of the table identified by `self.table_id`,
225233 and constructs a list of `Column` objects representing each field in the table.
226234
235+ Raises:
236+ TableNotFoundError: If the table is not found or cannot be retrieved.
237+
227238 Returns:
228239 list[Column]: A list of `Column` objects, each representing a column in the BigQuery table.
229240 """ # noqa: E501
230241 client = bigquery .Client ()
231- table = client .get_table (self .table_id )
242+ try :
243+ table = client .get_table (self .table_id )
244+ except Exception as e :
245+ logging .error (f"Failed to retrieve table '{ self .table_id } ': { e } " )
246+ raise TableNotFoundError (self .table_id ) from e
247+
232248 logging .debug (f"Got table schema from table { self .table_id } " )
233249 columns = [
234250 Column (
0 commit comments