btford/react-palm

I am trying to return an error but the error is not being propagated

macrigiuseppe opened this issue · 0 comments

While using a bimap with success and error callbacks and I try to use the error callback from within the task:

/* Action calling tasks */
export const loadFilesUpdater = (state, action) => {
  const {files} = action;

  const filesToLoad = files.map(fileBlob => processFileToLoad(fileBlob));

  // reader -> parser -> augment -> receiveVisData
  const loadFileTasks = [
    Task.all(filesToLoad.map(LOAD_FILE_TASK)).bimap(
      results => {
        const data = results.reduce((f, c) => ({
          // using concat here because the current datasets could be an array or a single item
          datasets: f.datasets.concat(c.datasets),
          // we need to deep merge this thing unless we find a better solution
          // this case will only happen if we allow to load multiple keplergl json files
          config: {
            ...f.config,
            ...(c.config || {})
          }
        }), {datasets: [], config: {}, options: {centerMap: true}});
        return loadFilesSuccess(data);
      },
      error => loadFilesErr(error)
    )
  ];

  return withTask(
    {
      ...state,
      visState: {
        ...state.visState,
        fileLoading: true
      }
    },
    loadFileTasks
  );
};
/* Load file Task */
export const LOAD_FILE_TASK = taskCreator(
  ({fileBlob, info, handler, processor}, success, error) =>
    handler(fileBlob, processor)
      .then(result => {
        !result ?
          error(new Error('Result is empty'))
          : result.datasets ?
            success(result)
            : success({datasets: {data: result, info}});
      })
      .catch(err => error(err)),
  'LOAD_FILE_TASK'
);

the bimap error callback is not being called.

But if i do the following

error(null)

the callback is being called correctly with null as paramenter.

I was digging around the react-palm code and i found out if I try to use the error callback with a non-null param the flow is being stopped here:

if (err) {