Skip to content

Commit 17445e4

Browse files
authored
feat: Improved validatePackage function (fixed bugs, added FK validation) (#179)
* Added fixture * Added test * Added concatFileStreams * Support multipart path in validateFile * Added aliases validateResource/PackageMetadata * Don't rais if can't load a table * Added encoding validation * Fixed test * Improved error message * Fixed polars encoding * Fixed fixture for issue #153 * Updated test * Fixed type erors * Fixed validateFile spec * Fixed inferFile spec * Fixed validateResourceCommand spec * Enable failing test * Fixed missing values being considered cell/type errors * Fixed cell/type-required duplication
1 parent 1557383 commit 17445e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+830
-214
lines changed

cli/commands/resource/validate.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ useRecording()
99

1010
describe("resource validate", () => {
1111
it("should validate a valid resource", async () => {
12+
const csvPath = await writeTempFile("id,name\n1,alice\n2,bob")
1213
const resourceContent = JSON.stringify({
1314
name: "test-resource",
14-
path: "data.csv",
15+
path: basename(csvPath),
1516
})
1617
const resourcePath = await writeTempFile(resourceContent)
1718

cli/commands/schema/infer.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,19 @@ export const inferSchemaCommand = new Command("infer")
7979
loadTable(resource, { denormalized: true }),
8080
)
8181

82+
if (!table) {
83+
session.terminate("Could not load table")
84+
process.exit(1)
85+
}
86+
8287
const inferredSchema = await session.task(
8388
"Inferring schema",
8489
inferSchemaFromTable(table, options),
8590
)
8691

8792
if (isEmptyObject(inferredSchema)) {
8893
session.terminate("Could not infer schema")
89-
process.exit(1) // typescript ignore never return type above
94+
process.exit(1)
9095
}
9196

9297
await session.render(inferredSchema, <SchemaGrid schema={inferredSchema} />)

cli/commands/table/convert.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ export const convertTableCommand = new Command("convert")
142142
loadTable(resource, options),
143143
)
144144

145+
if (!table) {
146+
session.terminate("Could not load table")
147+
process.exit(1)
148+
}
149+
145150
if (options.query) {
146151
table = queryTable(table, options.query)
147152
}

cli/commands/table/describe.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ export const describeTableCommand = new Command("describe")
9393
loadTable(resource, options),
9494
)
9595

96+
if (!table) {
97+
session.terminate("Could not load table")
98+
process.exit(1)
99+
}
100+
96101
if (options.query) {
97102
table = queryTable(table, options.query)
98103
}

cli/commands/table/explore.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ export const exploreTableCommand = new Command("explore")
9292
loadTable(resource, { denormalized: true }),
9393
)
9494

95+
if (!table) {
96+
session.terminate("Could not load table")
97+
process.exit(1)
98+
}
99+
95100
if (!schema && resource.schema) {
96101
schema = await session.task(
97102
"Loading schema",

cli/commands/table/script.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ export const scriptTableCommand = new Command("script")
9494
loadTable(resource, options),
9595
)
9696

97+
if (!table) {
98+
session.terminate("Could not load table")
99+
process.exit(1)
100+
}
101+
97102
if (options.query) {
98103
table = queryTable(table, options.query)
99104
}

cli/commands/table/validate.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ export const validateTableCommand = new Command("validate")
9999
loadTable(resource, { denormalized: true }),
100100
)
101101

102+
if (!table) {
103+
session.terminate("Could not load table")
104+
process.exit(1)
105+
}
106+
102107
if (!schema && resource.schema) {
103108
schema = await session.task(
104109
"Loading schema",

cloud/components/Report/Error/Error.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from "./Cell.tsx"
1515
import { FieldNameError, FieldTypeError } from "./Field.tsx"
1616
import { FieldsExtraError, FieldsMissingError } from "./Fields.tsx"
17-
import { BytesError, HashError } from "./File.tsx"
17+
import { BytesError, EncodingError, HashError } from "./File.tsx"
1818
import { MetadataError } from "./Metadata.tsx"
1919
import { RowUniqueError } from "./Row.tsx"
2020

@@ -31,6 +31,8 @@ export function Error(props: {
3131
return <BytesError error={error} />
3232
case "file/hash":
3333
return <HashError error={error} />
34+
case "file/encoding":
35+
return <EncodingError error={error} />
3436
case "fields/missing":
3537
return <FieldsMissingError error={error} />
3638
case "fields/extra":

cloud/components/Report/Error/File.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,20 @@ export function HashError(props: { error: errorTypes.HashError }) {
3535
</Text>
3636
)
3737
}
38+
39+
export function EncodingError(props: { error: errorTypes.EncodingError }) {
40+
const { t } = useTranslation()
41+
42+
return (
43+
<Text>
44+
{t("File encoding")} {t("is expected to be")}{" "}
45+
<Code fz="lg" fw="bold">
46+
{props.error.encoding}
47+
</Code>{" "}
48+
{t("but it is actually")}{" "}
49+
<Code fz="lg" fw="bold">
50+
{props.error.actualEncoding}
51+
</Code>
52+
</Text>
53+
)
54+
}

cloud/locales/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"are not expected": "werden nicht erwartet",
5252
"File size": "Dateigröße",
5353
"File hash": "Datei-Hash",
54+
"File encoding": "Datei-Kodierung",
5455
"Field name": "Feldname",
5556
"at": "bei",
5657
"The cell values of the fields": "Die Zellwerte der Felder",

0 commit comments

Comments
 (0)