I am trying to create a msi package from golang program with error logging feature. So, that I will be able to retrieve golang app crash logs.
The following Golang code is saved to main.go
, with a crash expected due to 1\0
division related error.
package main
import "fmt"
func main() {
// intentionally cause a divide-by-zero error
x := 0
y := 1 / x
fmt.Println(y)
}
Then I was trying to create msi package using following steps:
- step 1:
go get github.com/akavel/rsrc
- step 2:
rsrc -ico .\abc.ico
- step 3:
$Env:GOOS="windows"; go build -ldflags "-H windowsgui" -o ABC.exe
- step 4:
npm install electron-wix-msi@latest
- step 5:
npm install node-gyp@latest --save-dev
- step 6:
npm install child_process@latest --save-dev
- step 7:
npm install fs@0.0.1-security --save-dev
- step 8:
npm i exe-icon-extractor@latest --save-dev
Then I have created a javascript file name msi_creator.js
to generate msi package. The javascript code is as below:
const { MSICreator } = require("electron-wix-msi");
const path = require("path");
const { execSync } = require("child_process");
async function start() {
try {
// Step 2: Instantiate the MSICreator
const msiCreator = new MSICreator({
appDirectory: path.resolve("."),
description: "ABC",
exe: "ABC.exe",
name: "ABC",
manufacturer: "FFFF",
version: "0.1.0",
upgradeCode: "{12343238-1111-2222-3333-123483275556}",
removeExistingProduct: true,
iconPath: "./abc.ico",
outputDirectory: path.resolve("./output/"),
});
// Step 4: Create a .wxs template file
console.log("Creating the .wxs template file...");
await msiCreator.create();
console.log("Created the .wxs template file.");
// Step 5: Define the MSIErrorLog DLL function
console.log("Defining the MSIErrorLog DLL function...");
msiCreator.defineMsiErrorLogFunction(
function MSIErrorLog(hInstall) {
var exePath = session.property('CustomActionData');
var errorLogFile = session.property('MsiErrorLogFile');
try {
var child_process = require('child_process');
child_process.execFile(exePath, {stdio: 'ignore'}, function (error, stdout, stderr) {
if (error) {
var fs = require('fs');
var logFile = fs.createWriteStream(path.join(process.env['TEMP'], 'msi_error.log'), {flags: 'a'});
logFile.write('Error: ' + error.message + '\n');
logFile.end();
}
});
} catch (e) {
var fs = require('fs');
var logFile = fs.createWriteStream(path.join(process.env['TEMP'], 'msi_error.log'), {flags: 'a'});
logFile.write('Error: ' + e.message + '\n');
logFile.end();
}
}
);
console.log("Defined the MSIErrorLog DLL function.");
// Step 6: Compile the template to a .msi file
console.log("Compiling the .wxs template...");
await msiCreator.compile();
console.log("Compiled the .wxs template to an MSI installer.");
} catch (error) {
console.error(error);
}
}
start();
Then I run the command
node .\msi_creator.js
But I am getting the following error:
Created the .wxs template file.
Defining the MSIErrorLog DLL function...
TypeError: msiCreator.defineMsiErrorLogFunction is not a function
How to fix this issue? How can I store error logs related app crash?
Thanks and Regards, manu