Skip to content

Commit b02f592

Browse files
committed
refactor(typefusion): effect errors are already yieldable, don't need to wrap them with effect.fail
1 parent 4c6cede commit b02f592

File tree

4 files changed

+25
-37
lines changed

4 files changed

+25
-37
lines changed

packages/typefusion/src/db/clickhouse/types.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,10 @@ export const valueToClickhouseType = (
101101
case "boolean":
102102
return "Bool";
103103
default:
104-
return yield* Effect.fail(
105-
new UnsupportedJSTypeDbConversionError({
106-
cause: null,
107-
message: `Unsupported JS type in Clickhouse for provided value: ${typeof value}`,
108-
}),
109-
);
104+
return yield* new UnsupportedJSTypeDbConversionError({
105+
cause: null,
106+
message: `Unsupported JS type in Clickhouse for provided value: ${typeof value}`,
107+
});
110108
}
111109
});
112110

packages/typefusion/src/db/mysql/types.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,10 @@ export const valueToMySqlType = (
8484
case "boolean":
8585
return "BOOLEAN";
8686
default:
87-
return yield* Effect.fail(
88-
new UnsupportedJSTypeDbConversionError({
89-
cause: null,
90-
message: `Unsupported JS type in mysql for provided value: ${typeof value}`,
91-
}),
92-
);
87+
return yield* new UnsupportedJSTypeDbConversionError({
88+
cause: null,
89+
message: `Unsupported JS type in mysql for provided value: ${typeof value}`,
90+
});
9391
}
9492
});
9593

packages/typefusion/src/db/postgres/types.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,10 @@ export const valueToPostgresType = (
104104
case "boolean":
105105
return "BOOLEAN";
106106
default:
107-
return yield* Effect.fail(
108-
new UnsupportedJSTypeDbConversionError({
109-
cause: null,
110-
message: `Unsupported JS type in postgres for provided value: ${typeof value}`,
111-
}),
112-
);
107+
return yield* new UnsupportedJSTypeDbConversionError({
108+
cause: null,
109+
message: `Unsupported JS type in postgres for provided value: ${typeof value}`,
110+
});
113111
}
114112
});
115113

packages/typefusion/src/store.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,10 @@ const convertTypefusionScriptResultToSQLDDL = (
284284
// If no database types are provided, we will infer them from the result data
285285
if (!module.schema || Object.keys(module.schema).length === 0) {
286286
if (result.data.length === 0) {
287-
yield* Effect.fail(
288-
new ConvertDataToSQLDDLError({
289-
cause: null,
290-
message: `Your data for script '${module.name}' is empty, please add types for module '${module.name}'. We can't infer the database types from an empty result.`,
291-
}),
292-
);
287+
yield* new ConvertDataToSQLDDLError({
288+
cause: null,
289+
message: `Your data for script '${module.name}' is empty, please add types for module '${module.name}'. We can't infer the database types from an empty result.`,
290+
});
293291
}
294292
yield* Effect.logDebug(
295293
`No database types provided for module '${module.name}', inferring from first item in result data.`,
@@ -383,26 +381,22 @@ export const dbInsert = (module: TypefusionScriptExport, result: unknown) =>
383381
} else {
384382
if (!resultIsValidSchema) {
385383
yield* Effect.logError("Invalid script run result: ", result);
386-
yield* Effect.fail(
387-
new DatabaseInsertError({
388-
cause: null,
389-
message: `Module '${module.name}' does not match expected schema, make sure your run function returns an object with the following shape: ${ScriptResultSchema.toString()}`,
390-
}),
391-
);
384+
yield* new DatabaseInsertError({
385+
cause: null,
386+
message: `Module '${module.name}' does not match expected schema, make sure your run function returns an object with the following shape: ${ScriptResultSchema.toString()}`,
387+
});
392388
}
393389
if (!moduleIsValidSchema) {
394390
yield* Effect.logError(
395391
"Invalid module export: ",
396392
// We are going to assume that people at least provided a name
397393
(module as TypefusionScriptExport).name,
398394
);
399-
yield* Effect.fail(
400-
new DatabaseInsertError({
401-
cause: null,
402-
// We are going to assume that people at least provided a name
403-
message: `Module '${(module as TypefusionScriptExport).name}' does not match expected schema, make sure your script returns an object with the following shape: ${ScriptExportSchema.toString()}`,
404-
}),
405-
);
395+
yield* new DatabaseInsertError({
396+
cause: null,
397+
// We are going to assume that people at least provided a name
398+
message: `Module '${(module as TypefusionScriptExport).name}' does not match expected schema, make sure your script returns an object with the following shape: ${ScriptExportSchema.toString()}`,
399+
});
406400
}
407401
}
408402
});

0 commit comments

Comments
 (0)