Cannot Make New Job From Empty Folder

Post Reply
DtM
Member
Posts: 20
Joined: Tue Aug 04, 2015 3:02 pm

Cannot Make New Job From Empty Folder

Post by DtM » Thu Sep 16, 2021 11:27 am

Hello,

I have a script where I am potentially producing multiple files, but want them to be contained in a single folder on output.

Once I have ascertained that I will be producing multiple files, I try to create a new job based on a temporary folder as such:

Code: Select all

// If multiple files are possible, then make a folder to keep the files in for output.
if (multipleFiles) {
    const tmpFolder = await tmp.dir({ unsafeCleanup: true });
    const newJobFolder = await job.createChild(tmpFolder.path);
}
This however returns the error: "Creating job error: No file attached".

If change tmp.dir to tmp.file, I do not get the error, but obviously that doesn't help me with my requirements.

I have tried running in debug, creating a breakpoint on the tmpFolder line and can confirm that the folder is definitely being created.

Looking at the documentation here I can see that I should be able to supply a file or folder, but the latter just does not seem to work.

Can anyone please give me some advice?

Many thanks.

freddyp
Advanced member
Posts: 641
Joined: Thu Feb 09, 2012 3:53 pm

Re: Cannot Make New Job From Empty Folder

Post by freddyp » Thu Sep 16, 2021 1:12 pm

You do not mention what package you are using, but I assume it is tmp.

You would think, so did I when I first used the package, that the path to the temporary file/folder would be in the property .path but if you use the package I think you use, it is .name. That is not very logical, but who said that variable/property/function naming in programming is logical? The non-existent property .path results in undefined and that is why there is a problem.

Side remark: this is a typical problem you get when coding in JavaScript. An object instance variable followed by a dot and a property (or a function for that matter) is syntactically correct so JavaScript will accept that during coding, but it can fail at run-time. If you worked in TypeScript you would notice during the coding that .path is not valid for that object.

DtM
Member
Posts: 20
Joined: Tue Aug 04, 2015 3:02 pm

Re: Cannot Make New Job From Empty Folder

Post by DtM » Thu Sep 16, 2021 2:30 pm

Hi Freddy,

Apologies, my mistake for not clarifying - I am using tmp-promise which as the name would suggest is a wrapper for tmp that adds async await functionality.

Another thing that this wrapper does, is change the .name variable to .path (this also caught me off guard the first time I installed it!).

I have also confirmed this is the case in the debugger, putting a breakpoint after tmpFolder is created yields:

Code: Select all

tmpFolder: {
  path: "C:\\Users\\workflow\\AppData\\Local\\Temp\\2\\tmp-3280-q0JGV9zBr2Do",
  fd: 5,
  cleanup: function fn(...args) {
    return new Promise((resolve, reject) => {
      original.call(this, ...args, (err, ...values) => {
        if (err) {
          return reject(err);
        }
        if (argumentNames !== undefined && values.length > 1) {
          const obj = {};
          for (let i = 0; i < argumentNames.length; i++)
            obj[argumentNames[i]] = values[i];
          resolve(obj);
        } else {
          resolve(values[0]);
        }
      });
    });
  },
}

freddyp
Advanced member
Posts: 641
Joined: Thu Feb 09, 2012 3:53 pm

Re: Cannot Make New Job From Empty Folder

Post by freddyp » Thu Sep 16, 2021 3:38 pm

I have not tested it, so I will be assuming for a moment that creating a job from an empty folder does not work, and I think that is fine. At the moment you create a temporary folder, probably as opposed to a temporary file when multipleFiles == false, you have ascertained there will be multiple files.Well, put them there and only afterwards you create the child job from the folder.

Post Reply