1- import { flatten , isError , uniq , trim , sortBy , get , set } from 'lodash' ;
1+ import { flatten , isError , uniq , trim , sortBy , get , set , attempt } from 'lodash' ;
22import { List , fromJS , Set } from 'immutable' ;
33import * as fuzzy from 'fuzzy' ;
44import {
@@ -515,6 +515,7 @@ export class Backend {
515515 ) ,
516516 ) ;
517517 const formattedEntries = entries . map ( this . entryWithFormat ( collection ) ) ;
518+ // todo: find error somewhere here and put it to errors array
518519 // If this collection has a "filter" property, filter entries accordingly
519520 const collectionFilter = collection . get ( 'filter' ) ;
520521 const filteredEntries = collectionFilter
@@ -526,7 +527,7 @@ export class Backend {
526527 const groupedEntries = groupEntries ( collection , extension , filteredEntries ) ;
527528 return groupedEntries ;
528529 }
529-
530+ // todo: return object { entries, errors } + change all other processEntries uses to just take entries
530531 return filteredEntries ;
531532 }
532533
@@ -567,10 +568,14 @@ export class Backend {
567568 cursorType : 'collectionEntries' ,
568569 collection,
569570 } ) ;
571+
570572 return {
571573 entries : this . processEntries ( loadedEntries , collection ) ,
572574 pagination : cursor . meta ?. get ( 'page' ) ,
573575 cursor,
576+ errors : [
577+ 'error found in process entries'
578+ ]
574579 } ;
575580 }
576581
@@ -594,14 +599,17 @@ export class Backend {
594599 }
595600
596601 const response = await this . listEntries ( collection ) ;
597- const { entries } = response ;
602+ const { entries, errors } = response ;
598603 let { cursor } = response ;
599604 while ( cursor && cursor . actions ! . includes ( 'next' ) ) {
600605 const { entries : newEntries , cursor : newCursor } = await this . traverseCursor ( cursor , 'next' ) ;
601606 entries . push ( ...newEntries ) ;
602607 cursor = newCursor ;
603608 }
604- return entries ;
609+ return {
610+ entries,
611+ errors,
612+ } ;
605613 }
606614
607615 async search ( collections : Collection [ ] , searchTerm : string ) {
@@ -869,8 +877,12 @@ export class Backend {
869877 return ( entry : EntryValue ) : EntryValue => {
870878 const format = resolveFormat ( collection , entry ) ;
871879 if ( entry && entry . raw !== undefined ) {
872- const data = ( format && format . fromFile . bind ( format , entry . raw ) ( ) ) || { } ;
873- if ( isError ( data ) ) console . error ( data ) ;
880+ const data = ( format && attempt ( format . fromFile . bind ( format , entry . raw ) ) ) || { } ;
881+ // const data = (format && format.fromFile.bind(format, entry.raw)()) || {};
882+ if ( isError ( data ) ) {
883+ entry = Object . assign ( entry , { parseError : data . message } ) ;
884+ }
885+
874886 return Object . assign ( entry , { data : isError ( data ) ? { } : data } ) ;
875887 }
876888 return format . fromFile ( entry ) ;
0 commit comments