Skip to content

Commit

Permalink
fix: display error message on the frontend (risingwavelabs#8638)
Browse files Browse the repository at this point in the history
Signed-off-by: tabVersion <tabvision@bupt.icu>
Co-authored-by: lmatz <lmatz823@gmail.com>
  • Loading branch information
tabVersion and lmatz authored Mar 20, 2023
1 parent 1dee824 commit 44943ec
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,18 @@ public void validate(
String tableName = tableProperties.get(TABLE_NAME_PROP);
Set<String> jdbcColumns = new HashSet<>();
Set<String> jdbcPk = new HashSet<>();
Set<String> jdbcTableNames = new HashSet<>();

try (Connection conn = DriverManager.getConnection(jdbcUrl);
ResultSet tableNamesResultSet =
conn.getMetaData().getTables(null, null, "%", null);
ResultSet columnResultSet =
conn.getMetaData().getColumns(null, null, tableName, null);
ResultSet pkResultSet =
conn.getMetaData().getPrimaryKeys(null, null, tableName); ) {
while (tableNamesResultSet.next()) {
jdbcTableNames.add(tableNamesResultSet.getString("TABLE_NAME"));
}
while (columnResultSet.next()) {
jdbcColumns.add(columnResultSet.getString("COLUMN_NAME"));
}
Expand All @@ -72,6 +78,12 @@ public void validate(
throw Status.INTERNAL.withCause(e).asRuntimeException();
}

if (!jdbcTableNames.contains(tableName)) {
throw Status.INVALID_ARGUMENT
.withDescription("table not found: " + tableName)
.asRuntimeException();
}

// Check that all columns in tableSchema exist in the JDBC table.
for (String sinkColumn : tableSchema.getColumnNames()) {
if (!jdbcColumns.contains(sinkColumn)) {
Expand Down
22 changes: 19 additions & 3 deletions src/connector/src/sink/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,12 @@ impl<const APPEND_ONLY: bool> RemoteSink<APPEND_ONLY> {
})?;
let host_addr = HostAddr::try_from(&address).map_err(SinkError::from)?;
let client = ConnectorClient::new(host_addr).await.map_err(|err| {
SinkError::Remote(format!(
let msg = format!(
"failed to connect to connector endpoint `{}`: {:?}",
&address, err
))
);
tracing::warn!(msg);
SinkError::Remote(msg)
})?;

let table_schema = Some(TableSchema {
Expand All @@ -151,7 +153,21 @@ impl<const APPEND_ONLY: bool> RemoteSink<APPEND_ONLY> {
)
.await
.map_err(SinkError::from)?;
let _ = response.next().await.unwrap();
response.next().await.unwrap().map_err(|e| {
let msg = format!(
"failed to start sink stream for connector `{}` with error code: {}, message: {:?}",
&config.connector_type,
e.code(),
e.message()
);
tracing::warn!(msg);
SinkError::Remote(msg)
})?;
tracing::info!(
"{:?} sink stream started with properties: {:?}",
&config.connector_type,
&config.properties
);

Ok(RemoteSink {
connector_type: config.connector_type,
Expand Down

0 comments on commit 44943ec

Please sign in to comment.