All files / json-pack/src/nfs/v4/server/operations/node util.ts

92.3% Statements 12/13
83.33% Branches 5/6
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14      26x 29x   26x 10x 4x 4x 3x 3x    
import {Nfsv4Stat} from '../../..';
import type {Logger} from '../../types';
 
export const isErrCode = (code: unknown, error: unknown): boolean =>
  !!error && typeof error === 'object' && (error as any).code === code;
 
export const normalizeNodeFsError = (err: unknown, logger: Logger): Nfsv4Stat => {
  if (isErrCode('ENOENT', err)) return Nfsv4Stat.NFS4ERR_NOENT;
  Iif (isErrCode('EACCES', err)) return Nfsv4Stat.NFS4ERR_ACCESS;
  if (isErrCode('EEXIST', err)) return Nfsv4Stat.NFS4ERR_EXIST;
  logger.error('UNEXPECTED_FS_ERROR', err);
  return Nfsv4Stat.NFS4ERR_IO;
};