Cypress install and running - cypress

I am getting the following error/exception trying to run cypress:
Error: EEXIST: file already exists, mkdir
The tool runs and then throws up the error

The EEXIST error is another filesystem error that is encountered whenever a file or directory exists, but the attempted operation requires it not to exist. For example, you will see this error when you attempt to create a directory that already exists as shown below:
const fs = require('fs');
fs.mkdirSync('temp', (err) => {
if (err) throw err;
});
The solution here is to check if the path exists through fs.existsSync() before attempting to create it:
const fs = require('fs');
if (!fs.existsSync('temp')) {
fs.mkdirSync('temp', (err) => {
if (err) throw err;
});
}
Source: link

Related

Electron - Uncaught (in promise) Error: An object could not be cloned

I've this error when I click on my button:
Uncaught (in promise) Error: An object could not be cloned.
I start with electron, and I would like to take advantage of this topic to know the difference between invoke and send (I tried both, with the same error)
Main.js
ipcMain.handle('savePdf', (event, pdfFile) => {
console.log(event);
console.log(pdfFile);
return pdfFile;
}
preload.js
contextBridge.exposeInMainWorld('pdf', {
savePdf: (file) => ipcRenderer.invoke('savePdf', file),
})
rendered.js
const pdfFileInput = document.getElementById('input-file'); // OK
const pdfFile = pdfFileInput.files[0]; // OK
console.log(pdfFile); // OK
await pdf.savePdf(pdfFile);

AWS Textract does not run callback in error free run of analyzeDocument

CURRENTLY
I am trying to get AWS Textract working on a Lambda function and am following documentation on https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Textract.html#analyzeDocument-property
My Lambda code:
"use strict";
const AWS = require("aws-sdk");
exports.handler = async (event) => {
let params = JSON.parse(event.body);
console.log("Parse as document...");
let textract = new AWS.Textract();
let doc = params["doc"];
let config = {
Document: {
Bytes: doc,
}
};
textract.analyzeDocument(config, function (err, data) {
console.log("analyzing..."); //<-- nothing logged to console if no error
if (err) {
console.log(err, err.stack);
}
// an error occurred
else {
console.log("data:" + JSON.stringfy(data)); //<-- nothing logged to console if no error
} // successful response
});
console.log("Finished parsing as document.");
};
ISSUE
I cannot get the data back from Textract. It seems I am unable to get the callback working entirely. What's odd is if there is an error e.g. my configuration is wrong, the error handling of the callback will print the log and "analyzing..." log, but without error, none of the logs in the callback print.
Current Logs:
Parse as document...
Finished parsing as document.
Expected / Desired Logs:
Parse as document...
analyzing...
data:{textract output}
Finished parsing as document.
Please help!
NOTES
I am using a role for that Lambda that allows it to access Textract.
I get the same result whether I include the HumanLoopConfig settings or not.
Solved, apparently I needed to setup a promise:
let data = await textract.analyzeDocument(config).promise()
console.log("data:"+data );
console.log("Finished parsing as document.")

Electron fs - EPERM: operation not permitted, open 'C:\Windows\System32\drivers\etc\hosts'

Is there a way in electron or nodejs to ask the user to give permission to edit the file, e.g. like the popup if you want to install a program and you need the admin permissions to do so.
I don't have any problems reading the file with default permission settings. If I change the file permissions in the Windows explorer my electron app can write/edit the file, but that not solves my problem.
const fs = require("fs");
let letPathtoFile = "C:/Windows/System32/drivers/etc/hosts";
function funcReadFile() {
fs.readFile(letPathtoFile, function (err, data) {
if (err) {
return console.error(err);
}
$('#idReadFileContent').text(data);
});
}
function funcWriteFile() {
let letNewContent = $('#idWriteFileContent').val();
fs.writeFile(letPathtoFile, letNewContent, (err) => {
if (err) {
alert(err.message);
console.log(err);
return;
}
alert("File saved");
});
}
Yes, there is a way - you can use either sudo-prompt (NPM, GitHub) or electron-sudo (NPM, GitHub).
You'll need to do an exec command & a graphical OS prompt should show up.

How to ensure node.js child_process.spawn will write error messages to the console

I'm having a lot of trouble running child processes and getting their output written to the console. In this episode, I'm trying to use spawn to run a windows mklink command. The error is the that I don't have permission to write the file.
My problem, though, is that the error isn't told to me in any way.
The following prints You do not have sufficient privilege to perform this operation. to the console:
mklink /D C:\some\path\to\my\intended\link C:\path\to\my\folder
But running this in node.js only gives me Error: spawn ENOENT - which is a highly useless error message:
require('child_process').spawn('mklink',
['/D', 'C:\\some\\path\\to\\my\\intended\\link',
'C:\\path\\to\\my\\folder'],
{stdio:'inherit'})
I get nothing on the console, despite the stdio:'inherit'. I've also tried the following:
var x = require('child_process').spawn('mklink',
['/D', 'C:\\some\\path\\to\\my\\intended\\link',
'C:\\path\\to\\my\\folder'])
x.stdout.pipe(process.stdout)
x.stderr.pipe(process.stderr)
But no dice. No console output at all. Note that I do get console output with exec:
var x = require('child_process')
.exec('mklink /D C:\\some\\path\\to\\my\\intended\\link C:\\path\\to\\my\\folder')
x.stdout.pipe(process.stdout)
x.stderr.pipe(process.stderr)
This shouldn't need any special knowledge of how windows mklink works - my problem is simply with error reporting with node.js spawn.
What am I doing wrong here? Is this a bug in node.js?
Update: It seems this bug has been fixed by node v0.10.29
For me stdio wasn't working.
Try this:
// Helper function to execute and log out child process
// TODO: implement a better success/error callback
var spawnProcess = function(command, args, options, callback) {
var spawn = require('child_process').spawn;
var process = spawn(command, args, options),
err = false;
process.stdout.on('data', function(data) {
grunt.log.write(data);
});
process.stderr.on('data', function(data) {
err = true;
grunt.log.errorlns(data);
});
if (typeof callback === 'function') {
process.on('exit', function() {
if (!err) {
return callback();
}
});
}
};
spawnProcess('mklink', ['/D', 'C:\\some\\path\\to\\my\\intended\\link', 'C:\\path\\to\\my\\folder'], {}, done);
As a workaround, try the following:
require('child_process').spawn('cmd',
['/C', 'mklink', '/D', 'C:\\some\\path\\to\\my\\intended\\link',
'C:\\path\\to\\my\\folder'],
{stdio:'inherit'})

Permissions To Read Windows File Across Network in NodeJS

I'm trying to read a text file using NodeJS on a Mac. The file is on a Windows computer which is on the same network.
var fs = require('fs');
var file = "smb://someserver/stuff/names.txt";
fs.readFile(file, 'utf8', function(err, data) {
if (err) throw err;
console.log(data);
});
When I run this code, I get:
> Error: ENOENT, open 'smb://someserver/stuff/names.txt'
I probably need to authenticate access to the file, but I haven't found any docs or modules that deal with this scenario. Is it possible to read/write files like this?
Update (10/22)
I've tried using UNC paths (ie \\someserver\stuff\names.txt) but I believe that is only part of the solution. Somehow I need to supply username/password/domain because this file requires special permission. Is it possible to supply permissions somehow? For example:
var fs = require('fs');
var file = '\\someserver\stuff\names.txt';
var credentials = { username:'mydomain/jsmith', password:'password' }; ???
fs.readFile(file, 'utf8', function(err, data) {
if (err) throw err;
console.log(data);
});
You should use UNC paths if you are trying to access resources from other network drives.
var fs = require('fs');
var file = "\\someserver\stuff\names.txt";
fs.readFile(file, 'utf8', function(err, data) {
if (err) throw err;
console.log(data);
});
You can use the 'node-cmd' to update the credentials first and then try to read/write to the folder using the unc path.
var cmd = require("node-cmd");
const data = cmd.runSync(
"net use \\IP /user:username password"
);
// Now you do read / write using the fs
fs.readdir("\\IP")

Resources