Skip to content

Commit

Permalink
Add ErrorConfig to hold errors contacting locations.
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelbranco80 committed Aug 13, 2024
1 parent 3c5c420 commit 86bc8de
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions protocol/src/main/protobuf/raw/protocol/protocol.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ message LocationConfig {
DropboxUsernamePasswordConfig dropboxUsernamePassword = 14;
HttpHeadersConfig httpHeaders = 15;
SecretConfig secret = 99;
ErrorConfig error = 9999;
}
}

Expand Down Expand Up @@ -145,4 +146,8 @@ message HttpHeadersConfig {
message SecretConfig {
string name = 1;
string value = 2;
}

message ErrorConfig {
string message = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ object LocationDescription extends StrictLogging {
objectKey
)
)
case Some(l) if l.hasError => Left(l.getError.getMessage)
case None =>
// Anonymous access.
Right(S3PathLocationDescription(bucketName, None, None, None, objectKey))
Expand Down Expand Up @@ -651,6 +652,7 @@ object LocationDescription extends StrictLogging {
path
)
)
case Some(l) if l.hasError => Left(l.getError.getMessage)
case None => Left("missing Dropbox credential")
}
case _ => Left(s"unsupported protocol: $protocol")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class MySQLInferAndReadEntry extends SugarEntryExtension {
new MySqlTableLocation(l1.getHost, l1.getPort, l1.getDatabase, l1.getUser, l1.getPassword, table)(
programContext.settings
)
case Some(l) if l.hasError => Left(l.getError.getMessage)
case Some(_) => return Left("not a MySQL server")
case None => return Left(s"unknown credential: $db")
}
Expand Down Expand Up @@ -394,6 +395,7 @@ class MySQLInferAndQueryEntry extends SugarEntryExtension {
new MySqlServerLocation(l1.getHost, l1.getPort, l1.getDatabase, l1.getUser, l1.getPassword)(
programContext.settings
)
case Some(l) if l.hasError => Left(l.getError.getMessage)
case Some(_) => return Left("not a MySQL server")
case None => return Left(s"unknown credential: $db")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class OracleInferAndReadEntry extends SugarEntryExtension {
new OracleTableLocation(l1.getHost, l1.getPort, l1.getDatabase, l1.getUser, l1.getPassword, schema, table)(
programContext.settings
)
case Some(l) if l.hasError => Left(l.getError.getMessage)
case Some(_) => return Left("not an Oracle server")
case None => return Left(s"unknown credential: $db")
}
Expand Down Expand Up @@ -423,6 +424,7 @@ class OracleInferAndQueryEntry extends SugarEntryExtension {
new OracleServerLocation(l1.getHost, l1.getPort, l1.getDatabase, l1.getUser, l1.getPassword)(
programContext.settings
)
case Some(l) if l.hasError => Left(l.getError.getMessage)
case Some(_) => return Left("not an Oracle server")
case None => return Left(s"unknown credential: $db")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class PostgreSQLInferAndReadEntry extends SugarEntryExtension {
)(
programContext.settings
)
case Some(l) if l.hasError => Left(l.getError.getMessage)
case Some(_) => return Left("not a PostgreSQL server")
case None => return Left(s"unknown credential: $db")
}
Expand Down Expand Up @@ -433,6 +434,7 @@ class PostgreSQLInferAndQueryEntry extends SugarEntryExtension {
new PostgresqlServerLocation(l1.getHost, l1.getPort, l1.getDatabase, l1.getUser, l1.getPassword)(
programContext.settings
)
case Some(l) if l.hasError => Left(l.getError.getMessage)
case Some(_) => return Left("not an Oracle server")
case None => return Left(s"unknown credential: $db")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class SQLServerInferAndReadEntry extends SugarEntryExtension {
)(
programContext.settings
)
case Some(l) if l.hasError => Left(l.getError.getMessage)
case Some(_) => return Left("not an Oracle server")
case None => return Left(s"unknown credential: $db")
}
Expand Down Expand Up @@ -435,6 +436,7 @@ class SQLServerInferAndQueryEntry extends SugarEntryExtension {
new SqlServerServerLocation(l1.getHost, l1.getPort, l1.getDatabase, l1.getUser, l1.getPassword)(
programContext.settings
)
case Some(l) if l.hasError => Left(l.getError.getMessage)
case Some(_) => return Left("not an Oracle server")
case None => return Left(s"unknown credential: $db")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class SnowflakeInferAndReadEntry extends SugarEntryExtension {
)(
programContext.settings
)
case Some(l) if l.hasError => Left(l.getError.getMessage)
case Some(_) => return Left("not a Snowflake server")
case None => return Left(s"unknown credential: $db")
}
Expand Down Expand Up @@ -501,6 +502,7 @@ class SnowflakeInferAndQueryEntry extends SugarEntryExtension {
l1.getParametersMap,
programContext.settings
)
case Some(l) if l.hasError => Left(l.getError.getMessage)
case Some(_) => return Left("not a Snowflake server")
case None => return Left(s"unknown credential: $db")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ public LocationConfig getLocationConfig(String name) {
if (maybeLocationConfig.isEmpty()) {
throw new RawTruffleRuntimeException("unknown credential: " + name);
}
return maybeLocationConfig.get();
LocationConfig locationConfig = maybeLocationConfig.get();
if (locationConfig.hasError()) {
throw new RawTruffleRuntimeException(locationConfig.getError().getMessage());
}
return locationConfig;
}

@CompilerDirectives.TruffleBoundary
Expand Down

0 comments on commit 86bc8de

Please sign in to comment.