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

The Django CSRF token is inaccessible for retrieval

I'm in the process of developing a website using Vue.js for the frontend and Django for the backend. I've made sure to include the csrf token in every request from the frontend to the backend to prevent any 403 Forbidden errors. All requests are ...

Combine similar JSON objects into arrays

I'm working with a dataset returned by a library, and it's structured like this: var givenData = [{"fName": "john"}, {"fName": "mike"}, {"country": "USA"}] My goal is to group the "fName" values together and add '[]' to achieve the fo ...

I'm having trouble managing state properly in Safari because of issues with the useState hook

Encountering Safari compatibility issues when updating a component's state. Though aware of Safari's stricter mode compared to Chrome, the bug persists. The problem arises with the inputs: Whenever an option is selected from the dropdown, it cl ...

Include an Open OnClick event in the React/JSX script

We have a dynamic menu created using JavaScript (React/JSX) that opens on hover due to styling. My inquiries are: Instead of relying on CSS for the hover effect, where in the code can I implement an OnClick event to trigger the menu opening using Java ...

Utilizing Vue.js for Tabs in Laravel 5.8

I am encountering an issue in Laravel while attempting to set up a Vue instance for tabs. Currently, only Tab 1 and Tab 2 are displayed without any content, and the tabs themselves are not clickable links. Could this problem be related to how I am calling ...

Unable to deploy a sails.js application on an Amazon EC2 or DigitalOcean Ubuntu server using forever or pm2

After installing sails.js (v0.9.16) globally on amazon-ec2 / digitalocean ubuntu, I created a test project and successfully lifted the server: sudo npm -g install sails sails new sailstest cd sailstest sails lift I was able to access the sails app home ...

NPM rimraf - proceed with the execution even if directories are not found (do not halt with exit code 1)

My npm script is set up to run a series of synchronous commands, starting with npm run clean:install". Here is the sequence: "install:all": "npm install && bower install", "clean": "npm run rimraf -- node_modules doc typings coverage wwwroot bow ...

Issue: A request is not pending for flushing during the testing of an AngularJs service

As a beginner in AngularJs, I am currently working on my first unit test. In order to test the service I created, I wrote a test that simply returns a single Json object. However, whenever I run the test, I encounter the error mentioned in the title. I am ...

unable to assign values to this.props (appears as undefined or an empty array)

Upon setting up react/redux, I encountered a peculiar issue. When my component mounts, it should render the information stored in this.props.heroes.data. However, upon logging this data, I receive an unexpected value of [{id:1,heroname:'Batman',r ...

What is the process for deploying my Slack chatbot on Heroku?

I followed a tutorial to build my own Slack chatbot, and it was a success. Now, I am looking to host my bot on Heroku for continuous operation, but I cannot seem to find any information online on how to do so. The specific questions that I have are: Wh ...

Cast your vote once for each post within the Angular application

Currently, users are only able to vote up or down once in general. I would like to allow users to vote up or down once per post. <div ng-repeat="post in posts | orderBy:'-upvotes'"> <span class="glyphicon glyphicon-thumbs-up" ...

Create a single JSON object by searching through two collections in MongoDB

Is it possible for you to assist me in combining data from two collections into one JSON format? Users [ user_id, user_name, city_id ] [ { "name": "Anton", "user_id": 1, "city_id": 1 }, { "name": "Vasiliy", ...

Issues with Formik sign-up

Working on a study project involving React, Typescript, Formik, and Firebase presents a challenge as the code is not functioning correctly. While authentication works well with user creation in Firebase, issues exist with redirection, form clearing, and da ...

Update the JavaScript to modify the styling based on the specific value of the

Is there a way to apply specific style properties to images only if they already have another property? I've managed to achieve this with the following code snippet: if ($('#content p img').css('float') == 'right') $ ...

halt execution of npm test and erase any printed content

When I run npm test on my React project, it runs unit tests using jest and react testing library. The test logs (including console log lines added for debugging) are printed to the screen but get deleted after running the tests. It seems like the logs are ...

Transforming a numpy array of dimensions (M, N, O) into a point cloud

In my project, I am working with a large 3D numpy array measuring 2000 x 2000 x 300. This array consists of 300 binary images where pixel values are either 0 or 1. My goal is to obtain a new numpy array with dimensions P x 3, where P represents the number ...

Leveraging the power of Google Closure Templates alongside the versatility of

We are embarking on developing an application using JavaScript and HTML5 that will utilize a rest API to access server resources, leveraging the power and convenience of jQuery which our development team is already proficient in. Our goal is to make this a ...

Automatically inserting a row into an HTML table

My table structure looks like this: <form name="frm_data_nasabah2" method="post" enctype="application/x-www-form-urlencoded" action="<?php echo $page_action;?>"> <table class="table table-bordered table-hover" id="tab_logic_ ...

How can I use the import statement to incorporate the 'posts.routes.js' file into my app using app?

Searching high and low for answers but coming up empty. When setting up an express app and including a file of routes, you typically encounter guidance on using the following statement: require('./app/routes/posts.routes.js')(app) As per nodejs. ...

Using V-for in Vue.js to iterate over data sources

I am attempting to display all elements of an array, but currently can only show the first line due to [0]. I want to show all items in the array. <div class="description" v-for="item in sitePartVoice[0].part_attributes"> <small><strong> ...