sqlite3_1.default.database is not a constructor - electron

I installed in my Electron-React-Typescript-Webpack app sqlite3 via yarn: yarn add sqlite3#latest
and rebuilt everything with yarn electron-rebuild -f -w sqlite3
In webpack.config.js I've put:
const webpack = require('webpack');
externals: [
{
'sqlite3': sqlite3,
}
],
If in main.ts I put:
import sqlite3 from 'sqlite3';
let db = new sqlite3.Database(
path.join(app.getPath('userData'),'/infopiecesleveldb'),
(err) => {
if (err) {
return console.error(err.message);
}
console.log('Connected to the in-memory SQlite database.');
});
I get this error: sqlite3_1.default.database is not a constructor
(node:2679) UnhandledPromiseRejectionWarning: TypeError: sqlite3_1.default.database is not
a constructor
at App.<anonymous> (/home/marco/webMatters/electronMatters/Raphy-Template/dist/main
/main.js:60:32)
at App.emit (events.js:315:20)
(Use `electron --trace-warnings ...` to show where the warning was created)
(node:2679) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error
originated either by throwing inside of an async function without a catch block, or by
rejecting a promise which was not handled with .catch(). To terminate the node process on
unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see
https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2679) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In
the future, promise rejections that are not handled will terminate the Node.js process with
a non-zero exit code.
mainWindow loaded
Any ideas about how to solve it?

With
import sqlite3 from 'sqlite3';
//let db = new sqlite3.Database(':memory:', (err) => {
let db = new sqlite3.Database(
path.join(app.getPath('userData'),'/infopiecessql3db'),
(err) => {
if (err) {
return console.error(err.message);
}
console.log('Connected to the in-memory SQlite database.');
});
db.close();
now I get this message Connected to the in-memory SQlite database

Related

createMinToInstruction authorized by PDA, works fine in LocalNet, but gives "Account not associated with this Mint" when run on DevNet

I create an automate deployment script that will mint 2million SPL tokens to an address, the mint is owned by the program PDA as shown in Solana explorer:
Bellow is the last step in the deployment script:
export async function mint2e6Tokens(provider: anchor.AnchorProvider, tokenAccount: PublicKey, mint: PublicKey): Promise<void> {
// get the token account could be PDA
const programKeypair = await createKeypairFromFile(PROGRAM_KEYPAIR_PATH);
/** Load from PDA */
let mint_tokens_tx = new Transaction().add(
createMintToInstruction(
mint,
tokenAccount,
programKeypair.publicKey, // -> I DOUBLE CHECKED, THIS IS 6Z24B3qCrWfWvDo1f2HgxmnBSGhqQes1sHobqMtMxfbP
2e6,
[],
TOKEN_PROGRAM_ID
)
);
// We sign with our programId instead of the wallet because this is a PDA
// Program Derived Adress
await provider.sendAndConfirm(mint_tokens_tx, [programKeypair]);
}
When I run in LocalNet, it works:
Migrating to LocalNet...
RUNNING CUSTOM SCRIPT ====>>>
Payper: EsgJ9ihTEZskWyWpMMPuGVisy5ay76YWgetgTLb3jRmj
Using program 6Z24B3qCrWfWvDo1f2HgxmnBSGhqQes1sHobqMtMxfbP
Program: 6Z24B3qCrWfWvDo1f2HgxmnBSGhqQes1sHobqMtMxfbP
Mint: AVPgrT1y6ZfjGWPyLCWEPZdogRgmEMbrdRbcHNSfAPzF
Campaign: FcAmyEgZsXUKLB6hKufDmLuSBzMzVtPmRPm7vZLStK4U
31999500
However when I switch to DevNet, it always give me error
Migrating to DevNet...
RUNNING CUSTOM SCRIPT ====>>>
Payper: EsgJ9ihTEZskWyWpMMPuGVisy5ay76YWgetgTLb3jRmj
Using program 6Z24B3qCrWfWvDo1f2HgxmnBSGhqQes1sHobqMtMxfbP
Program: 6Z24B3qCrWfWvDo1f2HgxmnBSGhqQes1sHobqMtMxfbP
Mint: AVPgrT1y6ZfjGWPyLCWEPZdogRgmEMbrdRbcHNSfAPzF
Campaign: FcAmyEgZsXUKLB6hKufDmLuSBzMzVtPmRPm7vZLStK4U
SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x3
at Connection.sendEncodedTransaction (/code/beens/node_modules/#solana/web3.js/src/connection.ts:4248:13)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Connection.sendRawTransaction (/code/beens/node_modules/#solana/web3.js/src/connection.ts:4210:20)
at async sendAndConfirmRawTransaction (/code/beens/node_modules/#project-serum/anchor/src/provider.ts:288:21)
at async AnchorProvider.sendAndConfirm (/code/beens/node_modules/#project-serum/anchor/src/provider.ts:148:14) {
logs: [
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]',
'Program log: Instruction: MintTo',
'Program log: Error: Account not associated with this Mint',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2809 of 200000 compute units',
'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: custom program error: 0x3'
]
}
Why the authority is right, but Solana complain that Error: Account not associated with this Mint?
It turns out that my versions for Solana, Anchor and Rust are not compatible with DevNet and / or testnet.
I upgrade solana to main net recommended version and it works. One more things to mention that don't forget to run "solana program close --buffers" before trying. My current settings are:
root#d4c64206ce03:/code# solana --version
solana-cli 1.10.31 (src:77a40cd8; feat:4192065167)
root#d4c64206ce03:/code# rustc --version
rustc 1.63.0 (4b91a6ea7 2022-08-08)
root#d4c64206ce03:/code# anchor --version
anchor-cli 0.25.0

Can not get the readable electron crash reports on Sentry

I'm handling crashes in our electron app with crashReporter and sending reports to sentry.io.
The goal is to see which part of JS caused the app to crash. To emulate crash I'm doing "process.crash()". To see source code trace I'm installing sentry from it's documentation, but source code never appears in sentry.
Here is the CrashReporter initialization code:
crashReporter.start({
companyName: '...',
productName: '...',
uploadToServer: true,
submitURL: 'https://....ingest.sentry.io/api/.../minidump/?sentry_key=...'
});
Sentry is added to project as:
sentry-wizard --integration electron
npm install --save-dev #sentry/cli electron-download
node sentry-symbols.js
Webpack config:
const SentryWebpackPlugin = require('#sentry/webpack-plugin');
var config = {
target: 'node',
devtool: 'source-map',
plugins: [
new webpack.ProgressPlugin(),
new webpack.EnvironmentPlugin(),
new SentryWebpackPlugin({
include: '.',
ignoreFile: '.sentrycliignore',
ignore: ['node_modules', 'webpack.config.js'],
configFile: 'sentry.properties'
})
],
...
But this is how it looks on sentry:
You are producing a native crash, what you see here is a C++ stack trace which is symbolicated. Try to throw new Error('test'); in JavaScript somewhere, then you should see a JS stack trace.

Protractor Test Randomly Failing with Error "Failed: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:32572"

My Protractor test randomly fails with error . :
Failed: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:32572
at ClientRequest.<anonymous> (C:\jenkins\workspace\QA-E2E\automation\SeleniumFramework\node_modules\selenium-webdriver\http\index.js:238:15)
at ClientRequest.emit (events.js:223:5)
at Socket.socketErrorListener (_http_client.js:406:9)
at Socket.emit (events.js:223:5)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:81:21)
From: Task: WebDriver.navigate().to(data:text/html,<html></html>)
at Driver.schedule (C:\jenkins\workspace\QA-E2E\automation\SeleniumFramework\node_modules\selenium-webdriver\lib\webdriver.js:807:17)
at Navigation.to (C:\jenkins\workspace\QA-E2E\automation\SeleniumFramework\node_modules\selenium-webdriver\lib\webdriver.js:1133:25)
at Driver.get (C:\jenkins\workspace\QA-E2E\automation\SeleniumFramework\node_modules\selenium-webdriver\lib\webdriver.js:988:28)
at C:\jenkins\workspace\QA-E2E\automation\SeleniumFramework\node_modules\protractor\built\browser.js:675:32
at ManagedPromise.invokeCallback_ (C:\jenkins\workspace\QA-E2E\automation\SeleniumFramework\node_modules\selenium-webdriver\lib\promise.js:1376:14)
Node version : v12.14.1,
npm version : 6.13.4,
protractor version: 5.4.2,
webdriver-manager version: 12.1.6
Note : I am also using async/await in my test.
This was happening to me when I have more chromedriver.exe processes in background.
Terminate all processes in background or restart the computer and you should not see this error.
There used to be a problem some time ago when this error was specific to a some chromedriver, which had to resolved from selenium side. Since chromedriver 80 is a brand new version, I assume it's just a temporary bug which will be fixed some time soon
Meanwhile, you can try the solution that I used for a while. All you need is just to mute the error, by adding this code before exporting you config file
//////////////////////////////////////////////////////////////////////////////
// temporary work around to avoid 'ECONNREFUSED' error, preferably to find another solution
// remove the block when https://github.com/SeleniumHQ/selenium/pull/5759 will be merged && released
let httpIndexFile = "node_modules/selenium-webdriver/http/index.js";
fs.readFile(httpIndexFile, "utf8", function (err, data) {
if (err) {
throw err;
}
let result = data.replace(/\(e.code === 'ECONNRESET'\)/g, "(e.code === 'ECONNRESET' || e.code === 'ECONNREFUSED')");
console.log(`Patching ${httpIndexFile}`);
fs.writeFileSync(httpIndexFile, result, "utf8");
});
let chromeFile = "node_modules/selenium-webdriver/chrome.js";
fs.readFile(chromeFile, "utf8", function (err, data) {
if (err) {
throw err;
}
let result = data.replace(/new http.HttpClient\(url\)/g, "new http.HttpClient(url, new (require('http').Agent)({ keepAlive: true }))");
console.log(`Patching ${chromeFile}`);
fs.writeFileSync(chromeFile, result, "utf8");
});
//////////////////////////////////////////////////////////////////////////////
exports.config = {
Again, this was another problem, but the tweak should work the same

Hyperledger explorer starting problem- orderer port communication issue

I just started my hyperledger composer network. Now I need to start hyperledger explorer for this network. I already download the hyperledger explorer github repository using the link https://github.com/hyperledger/blockchain-explorer. I just try to start the explorer. But get the error in every time that
enter Please open web browser to access :http://localhost:9048/
pid is 31931
[31merror[39m: [Orderer.js]: sendDeliver - rejecting - status:NOT_FOUND
[31merror[39m: [Orderer.js]: sendDeliver - rejecting - status:NOT_FOUND
[31merror[39m: [Orderer.js]: sendDeliver - rejecting - status:NOT_FOUND
(node:31931) UnhandledPromiseRejectionWarning: Error: Invalid results returned ::NOT_FOUND
at ClientDuplexStream.<anonymous> (/home/myname/Pictures/blockchain-explorer-Production/node_modules/fabric-client/lib/Orderer.js:229:22)
at ClientDuplexStream.emit (events.js:180:13)
at addChunk (_stream_readable.js:274:12)
at readableAddChunk (_stream_readable.js:261:11)
at ClientDuplexStream.Readable.push (_stream_readable.js:218:10)
at readCallback (/home/myname/Pictures/blockchain-explorer-Production/node_modules/grpc/src/client.js:312:14)
(node:31931) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:31931) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:31931) UnhandledPromiseRejectionWarning: Error: Invalid results returned ::NOT_FOUND
at ClientDuplexStream.<anonymous> (/home/myname/Pictures/blockchain-explorer-Production/node_modules/fabric-client/lib/Orderer.js:229:22)
textProperty config.syncStartDate set to 2018/10/01
I think the error is due to orderer service.
I fully checked my orderer port in config.json file of hyperledger explorer.
{
"network-config": {
"org1": {
"name": "Org1",
"mspid": "Org1example",
"peer0": {
"requests": "grpc://192.168.1.49:7051",
"events": "grpc://192.168.1.49:7053",
"server-hostname": "peer0.org1.example.com",
"tls_cacerts": "/home/myname/Pictures/Kafka-Fabric-Network-master-3peer/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
},
"peer1": {
"requests": "grpc://192.168.1.49:9051",
"events": "grpc://192.168.1.49:9053",
"server-hostname": "peer1.org1.example.com",
"tls_cacerts": "/home/myname/Pictures/Kafka-Fabric-Network-master-3peer/crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt"
},
"admin": {
"key": "/home/myname/Pictures/Kafka-Fabric-Network-master-3peer/crypto-config/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp/keystore",
"cert": "/home/myname/Pictures/Kafka-Fabric-Network-master-3peer/crypto-config/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp/signcerts"
}
}
},
"channel": "examplechannel",
"orderers":[
{
"mspid": "OrdererOrg",
"server-hostname":"orderer0.example.com",
"requests":"grpc://192.168.1.49:7050",
"tls_cacerts":"/home/myname/Pictures/Kafka-Fabric-Network-master-3peer/crypto-config/ordererOrganizations/example.com/orderers/orderer0.example.com/tls/ca.crt"
}
],
"keyValueStore": "/tmp/fabric-client-kvs",
"configtxgenToolPath": "/home/myname/Pictures/Kafka-Fabric-Network-master-3peer/bin",
"SYNC_START_DATE_FORMAT":"YYYY/MM/DD",
"syncStartDate":"2018/08/01",
"eventWaitTime": "30000",
"license": "Apache-2.0",
"version": "1.1"
}
Fabric:1.1.0
Composer:0.19.16
OS: Ubuntu 16.04
Explorer: 0.3.4
How it solve. Please give me an idea to solve this issue. Thanks in advance

Electron - How to add react dev tool

What is the easy way to add react dev tool to electron window? I try add the extension hash
BrowserWindow.addDevToolsExtension('path/to/extension/ade2343nd23k234bdb').15.01
But when the extension update, I had to manually update the string in main.js. I'm looking for a better way.
Here is a Solution for Electron <= 1.2.1 version
1- In your app folder
npm install --save-dev electron-react-devtools
2- Open your electron app, click on (view/toggle developer tools). In the console tab insert the following code and hit enter:
require('electron-react-devtools').install()
3- Reload/refresh your electron app page and you'll see the react dev tools appear.
4- Done!
See screen shots bellow
You can add react devtools directly from your main.js file like this
const installExtensions = async () => {
const installer = require('electron-devtools-installer')
const forceDownload = !!process.env.UPGRADE_EXTENSIONS
const extensions = [
'REACT_DEVELOPER_TOOLS',
'REDUX_DEVTOOLS',
'DEVTRON'
]
return Promise
.all(extensions.map(name => installer.default(installer[name], forceDownload)))
.catch(console.log)
}
app.on('ready', async () => {
if (dev && process.argv.indexOf('--noDevServer') === -1) {
await installExtensions()
}
createWindow()
})
addDevToolsExtension is not an instance method, so you need to call BrowserWindow.addDevToolsExtension('path/to/extension').
Below solution worked for me (https://github.com/MarshallOfSound/electron-devtools-installer#usage) -
npm install electron-devtools-installer --save-dev
or
yarn add electron-devtools-installer -D
import installExtension, { REDUX_DEVTOOLS } from 'electron-devtools-installer';
// Or if you can not use ES6 imports
/**
const { default: installExtension, REACT_DEVELOPER_TOOLS } = require('electron-devtools-installer');
*/
const { app } = require('electron');
app.whenReady().then(() => {
installExtension(REDUX_DEVTOOLS)
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err));
});
If you see a blank component when launching react-devtools, it's probably because you've installed the package globally as it is recommended in the react-native docs, in the debugging section. What's happening is it doesn't get connected to your app, because it's not your app-specific.
You need to install it locally.
npm install --save-dev react-devtools
or
yarn add -D react-devtools

Resources