copyfiles icon indicating copy to clipboard operation
copyfiles copied to clipboard

Does not give error when copying fails

Open fatso83 opened this issue 8 years ago • 6 comments

Nothing happens when I run the following script. I don't get an error and no files are being produced.

#!/usr/bin/env node --harmony
const copyfiles = require('copyfiles');
const path = require('path');

const RAZOR_PATH = "Microsoft.AspNet.Razor.3.0.0/lib/net45/System.Web.Razor.dll"
const RAZORENG_PATH = "RazorEngine.3.8.2/lib/net45/RazorEngine.dll"
const JSON_PATH = "Newtonsoft.Json.8.0.3/lib/net45/Newtonsoft.Json.dll"
const destination = '.';
const paths = [ RAZOR_PATH, RAZORENG_PATH, JSON_PATH, destination ].map(path.normalize);
const opts = {};

copyfiles(paths, opts, function(err) {
    if(err) {
        console.error(`Failed copying dependencies: ${paths}`);
        process.exit(1);
    }

    console.log('.NET dependencies copied successfully')
});

fatso83 avatar Apr 27 '16 12:04 fatso83

it's not going to give an error if it can't find the paths so that's why it doesn't throw an error

calvinmetcalf avatar Apr 27 '16 13:04 calvinmetcalf

@calvinmetcalf: yeah but why not? It should throw or log a warning when the source path does not exist! It is completely unreliable otherwise ...

Tiliavir avatar Oct 12 '16 09:10 Tiliavir

That logic makes no sense. If missing files is not an error, then WTF is.

fatso83 avatar Oct 12 '16 10:10 fatso83

so we pass the paths to glob which tries to match them with paths on the hard drive, but a missing file just means a glob that doesn't match anything, which means we just don't put any files into the queue, so we could do a couple things

  1. throw an error if a glob doesn't produce any files, though this might be not great if somebody was just using it to transfer a bunch of directories not actually checking if anything was in them
  2. have it throw an error if nothing gets transferred at all, which would almost always be an error but might miss something
  3. do 2 by default but has an option for 1

calvinmetcalf avatar Oct 12 '16 12:10 calvinmetcalf

Ok that makes sense - I think adding a verbose flag, that logs a warning when a glob is not returning files would be sufficient for me - no idea what others think of this approach so...

Tiliavir avatar Oct 13 '16 09:10 Tiliavir

copyfiles does-not.exist out did not throw. so I'm here..

  • If copying a file without glob paths & file doesn't exist or fails — should definitely throw an error.
  • If nothing gets copied at all — should definitely throw an error.
  • If any defined glob does not produce any files and/or dirs — should definitely throw an error.

onury avatar Aug 25 '18 03:08 onury