I am trying to write to a CSV-file from my electron renderer.js process. Unfortunately, most of the time the writing isn't working, and the .then addition isn't executed. Strangely, there is no kind of error message or anything that would tell me my mistake. Some few times it has worked though, the file was written but the confirmation from .then wasn't displayed in the console. I don't have any clue as to what went differently these times.
When reloading the application with ctrl+r after the failed attempt the saving process is run again (somehow the onclick attribute of a button, containing a function call for the function all this stuff here ↓ is in) and that always works (including the .then call).
My code:
var settings = [
["devtools", false, devtools, ""],
["language", "en", language, ""]
]
var csvWriter = window.createCsvWriter({
header: ['ABBREVIATION', 'DEFAULT', 'CUSTOM', ''],
path: 'saves/settings.csv'
});
csvWriter.writeRecords(settings)
.then(() => {
console.log('Saved succesfully!');
});
window.createCsvWriter is a preloaded script, devtools and language are script wide variables that are updated shortly before this.
I have no idea where the error is coming from, as it can't be in the path or something like that as it has run successfully multiple times. I even tried to follow the debugging process line by line, but all I think I have found out is that the settings array is fully dealt with, the script ends somewhere in a jungle of loops and if-clauses concerning the path or something. I also know that a normal CSV-file wouldn't have a comma on the end of the rows, my code importing the settings later just can't deal with that, which I will fix later. If you need any more information just ask.
EDIT:
I just followed the code again line by line and notices that it stops after the return __awaiter() in CsvWriter.prptotype.writeRecords = function (records) {...}. records is an array with the correct data for the CSV. Maybe that is useful information.
EDIT2:
I tried using fs.writeFile() to write and it has the same problem, the file became empty and there was no error. I noticed though, that when reloading (remember originally it worked when reloading) it sent errors or confirmations for all the attempts of that session at once, and the file was written (if there were confirmations). So I assume the problem is something that stops the code from fully running until the page is reloaded. Any ideas what that could be? I imagine it's possible that it's another script or something global.
I don't have any breakpoints stopping the code.
consoleare you looking at? Therenderprocesses have their own console connected to the window.