Fixes wrong line number in logs

This commit is contained in:
freearhey 2023-10-11 18:16:24 +03:00
parent 1ea89eded0
commit ae2231547d
6 changed files with 24 additions and 18 deletions

14
package-lock.json generated
View file

@ -6,7 +6,7 @@
"": { "": {
"name": "@iptv-org/database", "name": "@iptv-org/database",
"dependencies": { "dependencies": {
"@freearhey/core": "^0.2.1", "@freearhey/core": "^0.2.2",
"@joi/date": "^2.1.0", "@joi/date": "^2.1.0",
"@json2csv/formatters": "^7.0.3", "@json2csv/formatters": "^7.0.3",
"@json2csv/node": "^7.0.3", "@json2csv/node": "^7.0.3",
@ -798,9 +798,9 @@
} }
}, },
"node_modules/@freearhey/core": { "node_modules/@freearhey/core": {
"version": "0.2.1", "version": "0.2.2",
"resolved": "https://registry.npmjs.org/@freearhey/core/-/core-0.2.1.tgz", "resolved": "https://registry.npmjs.org/@freearhey/core/-/core-0.2.2.tgz",
"integrity": "sha512-kEdIxZClykKhGpgyCSlkwuVuSCCAWr3J5YvOUMJQDPgVAYvT5VbD8MYKPm+OwNi9T4HFmF6qqY90qwKJPoOXCA==", "integrity": "sha512-8eikSh+alXohY/0Qv8lls+6BG738vOqxGuLvMjwBasbwuz8S/Abr7fUAH65dGjPAsB3HMaDhjK5c6kcVz5GrcA==",
"dependencies": { "dependencies": {
"@types/fs-extra": "^11.0.2", "@types/fs-extra": "^11.0.2",
"@types/lodash": "^4.14.198", "@types/lodash": "^4.14.198",
@ -6552,9 +6552,9 @@
"integrity": "sha512-NCC3zz2+nvYd+Ckfh87rA47zfu2QsQpvc6k1yzTk+b9KzRj0wkGa8LSoGOXN6Zv4lRf/EIoZ80biDh9HOI+RNQ==" "integrity": "sha512-NCC3zz2+nvYd+Ckfh87rA47zfu2QsQpvc6k1yzTk+b9KzRj0wkGa8LSoGOXN6Zv4lRf/EIoZ80biDh9HOI+RNQ=="
}, },
"@freearhey/core": { "@freearhey/core": {
"version": "0.2.1", "version": "0.2.2",
"resolved": "https://registry.npmjs.org/@freearhey/core/-/core-0.2.1.tgz", "resolved": "https://registry.npmjs.org/@freearhey/core/-/core-0.2.2.tgz",
"integrity": "sha512-kEdIxZClykKhGpgyCSlkwuVuSCCAWr3J5YvOUMJQDPgVAYvT5VbD8MYKPm+OwNi9T4HFmF6qqY90qwKJPoOXCA==", "integrity": "sha512-8eikSh+alXohY/0Qv8lls+6BG738vOqxGuLvMjwBasbwuz8S/Abr7fUAH65dGjPAsB3HMaDhjK5c6kcVz5GrcA==",
"requires": { "requires": {
"@types/fs-extra": "^11.0.2", "@types/fs-extra": "^11.0.2",
"@types/lodash": "^4.14.198", "@types/lodash": "^4.14.198",

View file

@ -22,7 +22,7 @@
"testRegex": "tests/(.*?/)?.*test.(js|ts)$" "testRegex": "tests/(.*?/)?.*test.(js|ts)$"
}, },
"dependencies": { "dependencies": {
"@freearhey/core": "^0.2.1", "@freearhey/core": "^0.2.2",
"@joi/date": "^2.1.0", "@joi/date": "^2.1.0",
"@json2csv/formatters": "^7.0.3", "@json2csv/formatters": "^7.0.3",
"@json2csv/node": "^7.0.3", "@json2csv/node": "^7.0.3",

View file

@ -129,11 +129,11 @@ async function main() {
} }
const schema = Joi.object(schemes[filename]) const schema = Joi.object(schemes[filename])
rows.forEach((row: string | string[] | boolean, i: number) => { rows.all().forEach((row: { [key: string]: string }, i: number) => {
const { error } = schema.validate(row, { abortEarly: false }) const { error } = schema.validate(row, { abortEarly: false })
if (error) { if (error) {
error.details.forEach(detail => { error.details.forEach(detail => {
fileErrors.push({ line: i + 2, message: detail.message }) fileErrors.push({ line: i + 2, row, message: detail.message })
}) })
} }
}) })
@ -142,7 +142,8 @@ async function main() {
logger.info(`\n${chalk.underline(filepath)}`) logger.info(`\n${chalk.underline(filepath)}`)
fileErrors.forEach(err => { fileErrors.forEach(err => {
const position = err.line.toString().padEnd(6, ' ') const position = err.line.toString().padEnd(6, ' ')
logger.info(` ${chalk.gray(position)} ${err.message}`) const id = err.row && err.row.id ? ` ${err.row.id}:` : ''
logger.info(` ${chalk.gray(position)}${id} ${err.message}`)
}) })
globalErrors = globalErrors.concat(fileErrors) globalErrors = globalErrors.concat(fileErrors)
} }

View file

@ -1,2 +1,2 @@
id,name,alt_names,network,owners,country,subdivision,city,broadcast_area,languages,categories,is_nsfw,launched,closed,replaced_by,website,logo id,name,alt_names,network,owners,country,subdivision,city,broadcast_area,languages,categories,is_nsfw,launched,closed,replaced_by,website,logo
002RadioTV.do,002 Radio TV,,,,DO,,,c/DO,spa,,FALSE,,,,https://www.002radio.com/,https://i.imgur.com/7oNe8xj.png 002RadioTV.do,002 Radio TV,,,,DO,,,c/DO,spa,,FALSE,,,,ttps://www.002radio.com/,https://i.imgur.com/7oNe8xj.png
1 id name alt_names network owners country subdivision city broadcast_area languages categories is_nsfw launched closed replaced_by website logo
2 002RadioTV.do 002 Radio TV DO c/DO spa FALSE https://www.002radio.com/ ttps://www.002radio.com/ https://i.imgur.com/7oNe8xj.png

View file

@ -68,8 +68,13 @@ describe('db:validate', () => {
process.exit(1) process.exit(1)
} catch (error) { } catch (error) {
expect((error as ExecError).status).toBe(1) expect((error as ExecError).status).toBe(1)
expect((error as ExecError).stdout).toContain('"aaa.us" is missing in the channels.csv') expect((error as ExecError).stdout).toContain(
expect((error as ExecError).stdout).toContain('1 error(s)') '2 "aaa.us" is missing in the channels.csv'
)
expect((error as ExecError).stdout).toContain(
'2 002RadioTV.do: "website" must be a valid uri with a scheme matching the http|https pattern'
)
expect((error as ExecError).stdout).toContain('2 error(s)')
} }
}) })

View file

@ -341,10 +341,10 @@
resolved "https://registry.npmjs.org/@eslint/js/-/js-8.50.0.tgz" resolved "https://registry.npmjs.org/@eslint/js/-/js-8.50.0.tgz"
integrity sha512-NCC3zz2+nvYd+Ckfh87rA47zfu2QsQpvc6k1yzTk+b9KzRj0wkGa8LSoGOXN6Zv4lRf/EIoZ80biDh9HOI+RNQ== integrity sha512-NCC3zz2+nvYd+Ckfh87rA47zfu2QsQpvc6k1yzTk+b9KzRj0wkGa8LSoGOXN6Zv4lRf/EIoZ80biDh9HOI+RNQ==
"@freearhey/core@^0.2.1": "@freearhey/core@^0.2.2":
version "0.2.1" version "0.2.2"
resolved "https://registry.npmjs.org/@freearhey/core/-/core-0.2.1.tgz" resolved "https://registry.npmjs.org/@freearhey/core/-/core-0.2.2.tgz"
integrity sha512-kEdIxZClykKhGpgyCSlkwuVuSCCAWr3J5YvOUMJQDPgVAYvT5VbD8MYKPm+OwNi9T4HFmF6qqY90qwKJPoOXCA== integrity sha512-8eikSh+alXohY/0Qv8lls+6BG738vOqxGuLvMjwBasbwuz8S/Abr7fUAH65dGjPAsB3HMaDhjK5c6kcVz5GrcA==
dependencies: dependencies:
"@types/fs-extra" "^11.0.2" "@types/fs-extra" "^11.0.2"
"@types/lodash" "^4.14.198" "@types/lodash" "^4.14.198"