Skip to content

fix: display error message on the frontend #8638

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

Merged
merged 4 commits into from
Mar 20, 2023
Merged
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 @@ -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