Skip to content

Commit

Permalink
fix: formatters exceptions throw error (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
semoal authored Nov 26, 2020
1 parent 3d54b4d commit d6b774c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions packages/cli/src/api/formats/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ const csv: CatalogFormatter = {
try {
return deserialize(raw)
} catch (e) {
console.error(`Cannot read ${filename}: ${e.message}`)
return null
throw new Error(`Cannot read ${filename}: ${e.message}`)
}
},
}
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/api/formats/lingui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ const lingui: CatalogFormatter = {
try {
return JSON.parse(raw)
} catch (e) {
console.error(`Cannot read ${filename}: ${e.message}`)
return null
throw new Error(`Cannot read ${filename}: ${e.message}`)
}
},
}
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/api/formats/minimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ const minimal: CatalogFormatter = {
const rawCatalog: Record<string, string> = JSON.parse(raw)
return deserialize(rawCatalog)
} catch (e) {
console.error(`Cannot read ${filename}: ${e.message}`)
return null
throw new Error(`Cannot read ${filename}: ${e.message}`)
}
},
}
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/api/formats/po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const deserialize: (item: Object) => Object = R.map(
)

type POItem = InstanceType<typeof PO.Item>
type PoFormatter = {
parse: (raw: string) => Object
}

const validateItems = R.forEach<POItem>((item) => {
if (R.length(getTranslations(item)) > 1) {
Expand All @@ -74,7 +77,7 @@ const validateItems = R.forEach<POItem>((item) => {

const indexItems = R.indexBy(getMessageKey)

const po: CatalogFormatter = {
const po: CatalogFormatter & PoFormatter = {
catalogExtension: ".po",

write(filename, catalog, options) {
Expand All @@ -99,7 +102,6 @@ const po: CatalogFormatter = {
return this.parse(raw)
},

// @ts-ignore
parse(raw) {
const po = PO.parse(raw)
validateItems(po.items)
Expand Down

1 comment on commit d6b774c

@vercel
Copy link

@vercel vercel bot commented on d6b774c Nov 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.