Skip to content

Commit 29a3560

Browse files
NicolappsConvex, Inc.
authored andcommitted
Improve the schema error messages from the Fivetran destination connector (#27233)
* Fixes an issue where `MissingTableWithoutSuggestion` would not show the correct error message * Stops `_creationTime` from showing in suggested indexes, since users aren’t allowed to add it manually in indexes * Add a trailing comma after the table definition so that users can copy/paste it in the middle of their `schema.ts` file GitOrigin-RevId: 7f5a18c8868e581510d120b603d78056beb0ef96
1 parent e4ab537 commit 29a3560

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

crates/fivetran_destination/src/error.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
use std::fmt::Display;
1+
use std::{
2+
fmt::Display,
3+
ops::Deref,
4+
};
25

36
use common::{
7+
document::CREATION_TIME_FIELD_PATH,
48
schemas::{
59
validator::{
610
FieldValidator,
@@ -66,7 +70,7 @@ Please edit your `schema.ts` file to add the table. You can use the following ta
6670
"The table `{0}` from your data source is missing in the schema of your Convex \
6771
destination.
6872
69-
Please edit your `schema.ts` file to add the table. You can use the following table definition:
73+
We are not able to suggest a schema because the following error happened:
7074
{1}"
7175
)]
7276
MissingTableWithoutSuggestion(TableName, Box<DestinationError>),
@@ -243,9 +247,9 @@ impl Display for SuggestedTable {
243247
.0
244248
.indexes
245249
.values()
246-
.map(|index| format!(" {}", SuggestedIndex(index.clone())))
250+
.map(|index| format!("\n {}", SuggestedIndex(index.clone())))
247251
.collect();
248-
let indexes = indexes.join("\n");
252+
let indexes = indexes.join("");
249253

250254
write!(
251255
f,
@@ -258,8 +262,7 @@ export default defineSchema({{
258262
259263
{table_name}: defineTable({{
260264
{fields}
261-
}})
262-
{indexes}
265+
}}){indexes},
263266
}});
264267
```",
265268
)
@@ -298,6 +301,7 @@ impl Display for SuggestedIndex {
298301
.0
299302
.fields
300303
.iter()
304+
.filter(|f| *f != CREATION_TIME_FIELD_PATH.deref())
301305
.map(|field| field.to_string())
302306
.collect();
303307
write!(
@@ -332,9 +336,13 @@ mod tests {
332336
fn it_formats_suggested_indexes() {
333337
let schema = IndexSchema {
334338
index_descriptor: "by_field_and_subfield".parse().unwrap(),
335-
fields: vec!["field".parse().unwrap(), "field.subfield".parse().unwrap()]
336-
.try_into()
337-
.unwrap(),
339+
fields: vec![
340+
"field".parse().unwrap(),
341+
"field.subfield".parse().unwrap(),
342+
"_creationTime".parse().unwrap(),
343+
]
344+
.try_into()
345+
.unwrap(),
338346
};
339347

340348
assert_eq!(
@@ -383,7 +391,7 @@ export default defineSchema({
383391
name: v.string(),
384392
})
385393
.index(\"by_email\", [\"email\"])
386-
.index(\"by_name\", [\"name\"])
394+
.index(\"by_name\", [\"name\"]),
387395
});
388396
```"
389397
.to_string(),

0 commit comments

Comments
 (0)