Skip to content
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
3 changes: 2 additions & 1 deletion cli/commands/resource/validate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ useRecording()

describe("resource validate", () => {
it("should validate a valid resource", async () => {
const csvPath = await writeTempFile("id,name\n1,alice\n2,bob")
const resourceContent = JSON.stringify({
name: "test-resource",
path: "data.csv",
path: basename(csvPath),
})
const resourcePath = await writeTempFile(resourceContent)

Expand Down
7 changes: 6 additions & 1 deletion cli/commands/schema/infer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,19 @@ export const inferSchemaCommand = new Command("infer")
loadTable(resource, { denormalized: true }),
)

if (!table) {
session.terminate("Could not load table")
process.exit(1)
}

const inferredSchema = await session.task(
"Inferring schema",
inferSchemaFromTable(table, options),
)

if (isEmptyObject(inferredSchema)) {
session.terminate("Could not infer schema")
process.exit(1) // typescript ignore never return type above
process.exit(1)
}

await session.render(inferredSchema, <SchemaGrid schema={inferredSchema} />)
Expand Down
5 changes: 5 additions & 0 deletions cli/commands/table/convert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ export const convertTableCommand = new Command("convert")
loadTable(resource, options),
)

if (!table) {
session.terminate("Could not load table")
process.exit(1)
}

if (options.query) {
table = queryTable(table, options.query)
}
Expand Down
5 changes: 5 additions & 0 deletions cli/commands/table/describe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ export const describeTableCommand = new Command("describe")
loadTable(resource, options),
)

if (!table) {
session.terminate("Could not load table")
process.exit(1)
}

if (options.query) {
table = queryTable(table, options.query)
}
Expand Down
5 changes: 5 additions & 0 deletions cli/commands/table/explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ export const exploreTableCommand = new Command("explore")
loadTable(resource, { denormalized: true }),
)

if (!table) {
session.terminate("Could not load table")
process.exit(1)
}

if (!schema && resource.schema) {
schema = await session.task(
"Loading schema",
Expand Down
5 changes: 5 additions & 0 deletions cli/commands/table/script.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ export const scriptTableCommand = new Command("script")
loadTable(resource, options),
)

if (!table) {
session.terminate("Could not load table")
process.exit(1)
}

if (options.query) {
table = queryTable(table, options.query)
}
Expand Down
5 changes: 5 additions & 0 deletions cli/commands/table/validate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ export const validateTableCommand = new Command("validate")
loadTable(resource, { denormalized: true }),
)

if (!table) {
session.terminate("Could not load table")
process.exit(1)
}

if (!schema && resource.schema) {
schema = await session.task(
"Loading schema",
Expand Down
4 changes: 3 additions & 1 deletion cloud/components/Report/Error/Error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from "./Cell.tsx"
import { FieldNameError, FieldTypeError } from "./Field.tsx"
import { FieldsExtraError, FieldsMissingError } from "./Fields.tsx"
import { BytesError, HashError } from "./File.tsx"
import { BytesError, EncodingError, HashError } from "./File.tsx"
import { MetadataError } from "./Metadata.tsx"
import { RowUniqueError } from "./Row.tsx"

Expand All @@ -31,6 +31,8 @@ export function Error(props: {
return <BytesError error={error} />
case "file/hash":
return <HashError error={error} />
case "file/encoding":
return <EncodingError error={error} />
case "fields/missing":
return <FieldsMissingError error={error} />
case "fields/extra":
Expand Down
17 changes: 17 additions & 0 deletions cloud/components/Report/Error/File.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,20 @@ export function HashError(props: { error: errorTypes.HashError }) {
</Text>
)
}

export function EncodingError(props: { error: errorTypes.EncodingError }) {
const { t } = useTranslation()

return (
<Text>
{t("File encoding")} {t("is expected to be")}{" "}
<Code fz="lg" fw="bold">
{props.error.encoding}
</Code>{" "}
{t("but it is actually")}{" "}
<Code fz="lg" fw="bold">
{props.error.actualEncoding}
</Code>
</Text>
)
}
1 change: 1 addition & 0 deletions cloud/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"are not expected": "werden nicht erwartet",
"File size": "Dateigröße",
"File hash": "Datei-Hash",
"File encoding": "Datei-Kodierung",
"Field name": "Feldname",
"at": "bei",
"The cell values of the fields": "Die Zellwerte der Felder",
Expand Down
1 change: 1 addition & 0 deletions cloud/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"are not expected": "are not expected",
"File size": "File size",
"File hash": "File hash",
"File encoding": "File encoding",
"Field name": "Field name",
"at": "at",
"The cell values of the fields": "The cell values of the fields",
Expand Down
1 change: 1 addition & 0 deletions cloud/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"are not expected": "no se esperan",
"File size": "Tamaño del archivo",
"File hash": "Hash del archivo",
"File encoding": "Codificación del archivo",
"Field name": "Nombre del campo",
"at": "en",
"The cell values of the fields": "Los valores de celda de los campos",
Expand Down
1 change: 1 addition & 0 deletions cloud/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"are not expected": "ne sont pas attendus",
"File size": "Taille du fichier",
"File hash": "Hash du fichier",
"File encoding": "Encodage du fichier",
"Field name": "Nom du champ",
"at": "à",
"The cell values of the fields": "Les valeurs de cellule des champs",
Expand Down
1 change: 1 addition & 0 deletions cloud/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"are not expected": "non sono previsti",
"File size": "Dimensione file",
"File hash": "Hash file",
"File encoding": "Codifica file",
"Field name": "Nome campo",
"at": "a",
"The cell values of the fields": "I valori delle celle dei campi",
Expand Down
1 change: 1 addition & 0 deletions cloud/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"are not expected": "não são esperados",
"File size": "Tamanho do arquivo",
"File hash": "Hash do arquivo",
"File encoding": "Codificação do arquivo",
"Field name": "Nome do campo",
"at": "em",
"The cell values of the fields": "Os valores das células dos campos",
Expand Down
1 change: 1 addition & 0 deletions cloud/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"are not expected": "не ожидаются",
"File size": "Размер файла",
"File hash": "Хеш файла",
"File encoding": "Кодировка файла",
"Field name": "Имя поля",
"at": "в",
"The cell values of the fields": "Значения ячеек полей",
Expand Down
1 change: 1 addition & 0 deletions cloud/locales/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"are not expected": "не очікуються",
"File size": "Розмір файлу",
"File hash": "Хеш файлу",
"File encoding": "Кодування файлу",
"Field name": "Ім'я поля",
"at": "в",
"The cell values of the fields": "Значення комірок полів",
Expand Down
7 changes: 2 additions & 5 deletions core/package/assert.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AssertionError } from "../error/index.ts"
import type { Descriptor } from "../general/index.ts"
import type { Package } from "./Package.ts"
import { validatePackageDescriptor } from "./validate.ts"
import { validatePackageMetadata } from "./validate.ts"

/**
* Assert a Package descriptor (JSON Object) against its profile
Expand All @@ -12,10 +12,7 @@ export async function assertPackage(
basepath?: string
},
) {
const { errors, dataPackage } = await validatePackageDescriptor(
source,
options,
)
const { errors, dataPackage } = await validatePackageMetadata(source, options)

if (!dataPackage) throw new AssertionError(errors)
return dataPackage
Expand Down
Loading