Issue encountered while attempting to write to csv-file using npm csv-writer - no error message displayed and function not working as

In my electron renderer.js process, I am attempting to write to a CSV file. Unfortunately, most of the time, the writing process doesn't work as expected, and the addition of .then is not executed. Despite this, no error messages or indications of mistakes are provided. Occasionally, the file is written successfully, but the confirmation message from .then does not appear in the console. The inconsistency leaves me puzzled.

Interestingly, upon reloading the application with ctrl+r after a failed attempt, the saving process reruns automatically (due to an onclick attribute of a button calling a function containing the problematic code) and always works, including the .then call.

Here's a snippet of 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 successfully!');
    });

The method window.createCsvWriter is a preloaded script, while devtools and language are variables updated prior to this section of code execution.

Despite several successful runs, I am unable to pinpoint the source of the issues. Even debugging line by line yielded no useful insights. The settings array seems to be processed correctly, but the script gets stuck in loops and if-conditions related to the path handling.

An issue worth mentioning is that my code creates CSV files with commas at the end of rows, causing problems during importing later on. This will require further attention. If additional information is needed, please feel free to ask.

EDIT: Upon scrutiny, I discovered that the code halts after the return __awaiter() statement in

CsvWriter.prototype.writeRecords = function (records) {...}
. The records array contains correct data for the CSV. Perhaps this detail could prove helpful.

EDIT2: I attempted using fs.writeFile() instead to address the issue, but encountered the same problem of an empty file without any errors. However, when reloading the page (where the code previously worked), multiple errors or confirmations were displayed for all attempts made in that session, indicating that the file was indeed written. It appears that something prevents the code from running completely until the page is reloaded. Could this be due to another global script interfering?

I do not have any breakpoints set in the code.

Answer №1

executeTasks provides a guarantee of either successful completion or failure. Your current implementation only considers the successful scenario and disregards any potential failures. To troubleshoot, consider implementing the following adjustment:

taskExecutor.executeTasks(config)
    .then(() => {
        console.log('Tasks completed successfully!');
    })
    .catch((error) => {
        console.log('Tasks failed to complete', error);
    });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Generating a new root in React 18 results in numerous rounds of rendering and execution

Every time I attempt to run this code in React 18, it seems to render multiple times unlike React 17 where it only executes once and functions properly. How can I modify the code so that it only runs once? Is there a specific reason for the multiple execu ...

AngularJS Service failing to appear on screen

I am trying to access my Github information using Github's API. I can see the correct information when I log my http request, but for some reason it is not showing up on the page. There are no errors being thrown, but the requested data is not display ...

Use React to increment a variable by a random value until it reaches a specific threshold

I am currently working on creating a simulated loading bar, similar to the one seen on YouTube videos. My goal is for it to last 1.5 seconds, which is the average time it takes for my page to load. However, I have encountered an issue with the following co ...

Disable reloading when submitting and reset input fields after submission

I am working on developing a website where users can post things and comments without the need to refresh the page. I have encountered some issues while implementing this feature and need some assistance with it. My goal is to allow users to submit comment ...

What is the best way to conceal a website's URL?

Is it possible to hide the actual URL some.otherdomain.com and show only domain.com to visitors of my website? I am looking for a way to mask the URL, perhaps through .htaccess or javascript. Is there any solution available? ...

Obtain the names of the cities that the Google Maps route passes through

Currently working on a website that integrates Google Map API v3. Is there a method to gather the names of the places or cities along the route from point A to B? The page utilizes JavaScript for functionality. ...

The Quivering Quandaries of Implementing Jquery Accordions

For a demonstration of the issue, please visit http://jsbin.com/omuqo. Upon opening a panel by clicking on the handle, there is a slight jitter in the panels below during the animation. In the provided demo, all panels should remain completely still as t ...

The reason why the script and div tags are so common in HTML is because they serve different purposes. However, it's

Hey there, friend! I've searched on baidu.com, cnds, and stack overflow, but couldn't find an answer. I have two questions: "why can script and div tags be used so much in HTML?" and "why is there only one html and body tag in HTML?" For example: ...

I am unable to install npm or node js within the git bash directory labeled phaser3-project-template

Every time I enter npm install in my Git Bash terminal, an error message pops up saying: > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d5a0b2b9bcb3acbfa6f8a2b0b7a5b4b6bef8a5b9a0b2bcbb95e5fbe1fbe3">[email protected ...

Discord bot that combines the power of discord.js and node.js to enhance your music

I am currently working on a Discord bot designed to play music in voice chat rooms. However, I am facing some issues with properties. Whenever I try to launch the bot using "node main", I encounter the following error message: "TypeError: Cannot read prope ...

Incorporating a dynamic fill effect into an SVG pie chart

I am looking to animate a pie chart with a variable value that is unknown upon loading. Assuming I fetch the value promptly and convert it into a rounded percentage : var percentage = Math.round(sum * 100 / total); Next, I place this value here : <di ...

Interactive div containing elements that cannot be clicked

http://codepen.io/anon/pen/zxoYBN To demonstrate my issue, I created a small example where there is a link button within a div that toggles another div when clicked. However, I want the link button to not trigger the toggle event and be excluded from the ...

Using React/NextJS: What is the best way to handle mapping through an array of objects with dynamic keys?

I am currently working on a project in NextJS and have encountered an interesting challenge that I'm struggling to solve. The issue revolves around dealing with an array of objects obtained from the Civic GAPI. Within this array, there are objects rep ...

Tips for effectively dividing React application components

Jumping into React to build an application seemed like a good idea at first, but now I realize the complexity of it. Let me walk you through my plan and see if it aligns with best practices: The goal is to develop a React App for organizing the subjects I ...

What is the best way to concatenate a data object?

This task should be quite straightforward. Using Vanilla JS, I am trying to update the content of a span element with the session ID obtained from a function call. Here's an example: sessionId = 0_77b1f7b5-b6c8-49a0-adbc-7883d662ebba document.getEle ...

Using Node.js and Multer to update a file uploaded to MongoDB

I have a website that allows users to upload files, but I also want them to be able to edit those files. This would involve the user pressing "edit" and replacing the existing file in the database with a new one. Normally, you can use findByIdAndUpdate for ...

Add the item to a fresh array using the Ajax function

Here is an array that I have: var arrayOfResults = []; // Results after like statement After making a database call, I receive a JSON result like this: [{ "id": "{fcb42c9c-3617-4048-b2a0-2600775a4c34}", "pid": "{34214CCB-90C3-4D ...

encountering a glitch while using console.log(util.format

Let me start by saying that I am fairly new to working with node.js. A friend of mine assisted me in writing the code snippet below. I have successfully installed the necessary packages search-google-geocode, csv-parser, fs, util, and async using npm. H ...

Convert a JSON object into a string using Node.js

Here is my code snippet: app.get('/status',function ( req,res) { var data = { "error": 1, 'data status': "" }; connection.query("SELECT * from status", function (err, rows, fields) { ...

Issue with loading Three.js asynchronously

My attempt to determine the maximum value of a point cloud data using the following code proved unsuccessful. import { PLYLoader } from "three/examples/jsm/loaders/PLYLoader"; let max_x = -Infinity; function initModel() { new PLYLoader().load ...