I have a github workflow where I want to filter the terraform destroy changes from the terraform plan file and post that as comment in the PR.
- name: Terraform Plan
id: plan_json
run: |
terraform plan -out planfile 2>error.log
terraform show -json planfile > plan.json
continue-on-error: true
- uses: actions/github-script#v5
id: message
if: ${{ always() }}
with:
result-encoding: string
script: |
const fs = require('fs');
const report = JSON.parse(fs.readFileSync('./plan.json'));
var message = '';
for (const changes in report.resource_changes) {
message += `${changes.change.actions[0]} ${changes.name} (${changes.type})\n`
};
console.log('Message: ', message);
return message;
When I run the workflow it gives this error:
SyntaxError: Unexpected token c in JSON at position 1
at JSON.parse (<anonymous>)
at eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:4942:56), <anonymous>:4:21)
at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:4943:12)
Error: Unhandled error: SyntaxError: Unexpected token c in JSON at position 1
at main (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:4997:26)
at Module.272 (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:4981:1)
at __webpack_require__ (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:24:31)
at startup (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:43:19)
at /home/runner/work/_actions/actions/github-script/v5/dist/index.js:49:18
at Object.<anonymous> (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:52:10)
at Module._compile (internal/modules/cjs/loader.js:959:30)
I don't have any nodejs/javascript experience so I have no clue what I am doing wrong here.
The actual plan file can be found here.
When I run the nodejs script locally it works.
❯ node tfplan.js
Message: create, rg (azurerm_resource_group)
create, rg-name (random_pet)
- uses: hashicorp/setup-terraform#v1
with:
terraform_wrapper: false
terraform_wrapper: false had to be added to the terraform setup task.
For more info check this.
Related
I wanted to mock api calls in storybook by using the msw package in my storybook.
but when i try to launch it i get an error.
ModuleParseError: Module parse failed: Unexpected character '#' (14:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| */
| class Emitter {
> #events;
| #maxListeners;
| #hasWarnedAboutPotentialMemortyLeak;
at handleParseError (\node_modules\#storybook\builder-webpack4\node_modules\webpack\lib\NormalModule.js:469:19)
at \node_modules\#storybook\builder-webpack4\node_modules\webpack\lib\NormalModule.js:503:5
at \node_modules\#storybook\builder-webpack4\node_modules\webpack\lib\NormalModule.js:358:12
at \node_modules\loader-runner\lib\LoaderRunner.js:373:3
at iterateNormalLoaders (\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
at Array.<anonymous> (\node_modules\loader-runner\lib\LoaderRunner.js:205:4)
at Storage.finished (\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
at \node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
at \node_modules\graceful-fs\graceful-fs.js:123:16
at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)
ModuleParseError: Module parse failed: Unexpected token (5:11)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| exports.MemoryLeakError = void 0;
| class MemoryLeakError extends Error {
> emitter;
| type;
| count;
at handleParseError (\node_modules\#storybook\builder-webpack4\node_modules\webpack\lib\NormalModule.js:469:19)
at \node_modules\#storybook\builder-webpack4\node_modules\webpack\lib\NormalModule.js:503:5
at \node_modules\#storybook\builder-webpack4\node_modules\webpack\lib\NormalModule.js:358:12
at \node_modules\loader-runner\lib\LoaderRunner.js:373:3
at iterateNormalLoaders (\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
at Array.<anonymous> (\node_modules\loader-runner\lib\LoaderRunner.js:205:4)
at Storage.finished (\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
at \node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
at \node_modules\graceful-fs\graceful-fs.js:123:16
at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)
WARN Broken build, fix the error above.
WARN You may need to refresh the browser.
heres my storybook config
// https://storybook.js.org/docs/react/builders/webpack#typescript-module-resolution
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
module.exports = {
stories: ["../src/**/*.stories.tsx", "../src/**/*.stories.mdx"],
addons: [
"#storybook/preset-create-react-app",
"#storybook/addon-actions",
"#storybook/addon-links",
"#storybook/addon-controls",
"#storybook/addon-knobs",
"#storybook/addon-docs",
],
webpackFinal: async (config) => {
config.resolve.plugins = [
...(config.resolve.plugins || []),
new TsconfigPathsPlugin({
extensions: config.resolve.extensions,
}),
];
return config;
},
};
im using storybook v6.5.13, i tried using webpack5 since i noticed a lot of the articles explaning how to use msw had it, so i added
core : {
builder : "webpack5"
}
and the webpack manager + builder, but it just hangs there and never finishes building, so i reverted back.
I wrote a simple smart contract in Solidity 0.6.6 that I'm trying to deploy to the BSC Testnet.
This is what I have in my truffle-config.js file (privateKeys is an array with a single entry of ['0x + privatekey']:
networks: {
bscTestnet: {
provider: () => new HDWalletProvider(
privateKeys,
'https://data-seed-prebsc-1-s1.binance.org:8545/'
),
network_id: 97,
skipDryRun: true
}
}
When I run the command "truffle migrate --reset --network bscTestnet" I get the following error:
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Starting migrations...
======================
> Network name: 'bscTestnet'
> Network id: 97
> Block gas limit: 30000000 (0x1c9c380)
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
Error: *** Deployment Failed ***
"Migrations" -- cb is not a function.
at /Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:365:1
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at Migration._deploy (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:70:1)
at Migration._load (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:56:1)
at Migration.run (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:217:1)
at Object.runMigrations (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
at Object.runFrom (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
at Object.runAll (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:114:1)
at Object.run (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:79:1)
at runMigrations (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:80:1)
at Object.module.exports [as run] (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:44:1)
at Command.run (/Users/admin/.nvm/versions/node/v17.4.0/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:189:1)
Truffle v5.4.31 (core: 5.4.31)
Node v17.4.0
Opened an Issue a about it: https://github.com/trufflesuite/truffle/issues/4676
I guess its a bug in HardwareWallet2.0.2.
Reverting to HardwareWallet2.0.0 solved the problem for me
npm i #truffle/hdwallet-provider#2.0.0
UPDATE:
Right, workaround: I rolled #HDWalletProvider back to v2.0.1 and was able to migrate.
I assume there must be an issue with the new version for ppl who updated today.
================
Same problem with Polygon Mumbai.
Function "cb" refers to the callback function. The strange part is the error message doesn't reference my own code at all; it references the migrations.js located in:
<.nvm/versions/node/v16.11.1/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:365:1
at processTicksAndRejections (node:internal/process/task_queues:96:5>
This leads me to believe there's a problem with out 1_initial_migration.js... however that's auto-generated so I can't see any problem... it's strange.
1_initial_migration.js:
const Migrations = artifacts.require("Migrations");
module.exports = function(deployer) {
deployer.deploy(Migrations);
};
I am currently learning Javascript/HTML/CSS in order to build some data dashboard.
I have found this tutorial https://d3-dashboard.cube.dev/setting-up-a-database-and-cube-js
Currently I am getting stuck at this part:
The next step is to create a Cube.js data schema.
When opening the Cube.js playground at: http://localhost:4000, I get the following output in my terminal:
🦅 Dev environment available at http://localhost:4000, I get the following error:
🚀 Cube.js server (0.21.1) is listening on 4000
Error: getaddrinfo ENOTFOUND <YOUR_DB_HOST_HERE>
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26)
And in the Cube.js playground webpage view:
Error while loading DB schema
Error: getaddrinfo ENOTFOUND <YOUR_DB_HOST_HERE> at
GetAddrInfoReqWrap.onlookup [as oncomplete](dns.js66:26)
I have edited the following file:
d3-dashboard/node_modules/#cubejs-backend/server-core/core/index.js
, with:
const checkEnvForPlaceholders = () => {
const placeholderSubstr = '<YOUR_DB_';
const credentials = [
'CUBEJS_API_SECRET=SECRET',
'CUBEJS_DB_TYPE=postgres',
'CUBEJS_DB_NAME=ecom',
'CUBEJS_WEB_SOCKETS=true'
/*'CUBEJS_DB_HOST',*/
/*'CUBEJS_DB_NAME',*/
/*'CUBEJS_DB_USER',*/
/*'CUBEJS_DB_PASS'*/
];
Any input on what I am doing wrong here?
I am totally new to apps and front-ends, so it might be something "stupid" that I am sking, but I really would like to learn from my mistakes :)
Thank you for your time and potential inputs/help!
Have a great day :)
You definitely should not edit any files in the node_modules directory. You should store the env variables in the .env file.
-your-cubejs-server-root
--schema
--.env
--//..
And it may look like
CUBEJS_DB_HOST=localhost
CUBEJS_DB_NAME=cubejs
CUBEJS_DB_USER=root
CUBEJS_DB_PASS=
CUBEJS_DB_TYPE=mysql
CUBEJS_API_SECRET=secret
The error you're getting is saying that the connection to the DB cannot be established. Because you're missing the proper CUBEJS_DB_HOST= variable.
The minimum required set of variables differs for each database and can be found here https://cube.dev/docs/connecting-to-the-database
I am currently working on a new discord bot for my server and I've just started utilising .js files to store permanent data. I have set up a system to log attendees of a raid by typing "[Finished] etc... If the .js file where I am storing the data is empty everything works fine and all the data is correctly written to the file. However, if the bot restarts and then the .js file already contains data on other attendees and I attempt to write new data to that file it will throw me the "Unexpected Token" error.
I've attempted using fs.writeFileSync() but that doesn't seem to fix it, I've done a lot of research but can't seem to find a specific answer for my question.
Empty file to write to:
{
}
File when data is already there:
{
"2887482348774": {
"amount": 1
},
"1746782476348": {
"amount": 1
}
}
Fake discord IDs.
Command Code:
const Discord = require('discord.js');
const fs = require('fs');
module.exports.run = async (bot, message, args) => {
bot.msgs = require("./raiddata/raidattendance.js");
if (message.channel.id !== '631620937418145802') return;
if (!message.member.roles.some(r => ["Raider in Command", "Permissions"].includes(r.name))) return;
for (let attenders of message.mentions.users.keyArray()) {
message.channel.send(`Found user: ${attenders}`);
bot.msgs [attenders] = {
amount: 1
}
console.log("Works");
fs.writeFileSync ('./commands/raiddata/raidattendance.js', JSON.stringify (bot.msgs, null, 4), err => {
if (err) throw err;
});
message.channel.send(bot.msgs[attenders].amount);
}
}
module.exports.config = {
command: "finished]"
}
I expect the code to just continue to write to the file from where it left off but it doesn't. Here is the error I get:
8 commands found.
Command announcement.js loading...
Command changelog.js loading...
Command delete.js loading...
Command lock.js loading...
Command lograid.js loading...
Command notice.js loading...
Command raid.js loading...
Command unlock.js loading...
Bot is now running.
(node:6896) UnhandledPromiseRejectionWarning: C:\Users\Removed\Downloads\Removed\Removed\commands\raiddata\raidattendance.js:2
"1746782476348": {
^
SyntaxError: Unexpected token :
at Module._compile (internal/modules/cjs/loader.js:721:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
The problem is you're using require() to read in a json file with .js extension. This is not expected. If you change the file to have a .json extension, it'll fix the issue.
You may want to read the file in using the fs module instead of using require() as it will give greater flexibility and probably better practice.
I am following this quite lengthy but very informative post about setting up a web application using the following technology stack:
es 6
node + express
handlebars
react + react router
webpack + babel
The sample code can be found here.
I have been following along and it went quite well, I did understand the most important concepts. However, I am getting an error when I am trying to run it (after I downloaded it using git clone) like so:
$ npm install
$ npm start
The generated output including the error is:
> react-ssr-example#0.0.1 start /Users/nburk/Developer/node/templates/react-universal-web-apps-simple
> npm-run-all --parallel gulp server
> react-ssr-example#0.0.1 server /Users/nburk/Developer/node/templates/react-universal-web-apps-simple
> node-dev app/babel-server.js
> react-ssr-example#0.0.1 gulp /Users/nburk/Developer/node/templates/react-universal-web-apps-simple
> gulp
[19:10:39] Using gulpfile ~/Developer/node/templates/react-universal-web-apps-simple/gulpfile.js
[19:10:39] Starting 'build:scss'...
[19:10:39] Starting 'build:watch:app'...
TypeError: Cannot read property 'filename' of undefined
at Object.obj.(anonymous function) [as runInThisContext] (/Users/nburk/Developer/node/templates/react-universal-web-apps-simple/node_modules/node-dev/lib/hook.js:25:55)
at Object.<anonymous> (/Users/nburk/Developer/node/templates/react-universal-web-apps-simple/node_modules/graceful-fs/fs.js:10:13)
at Module._compile (module.js:425:26)
at Module._extensions..js (module.js:432:10)
at nodeDevHook (/Users/nburk/Developer/node/templates/react-universal-web-apps-simple/node_modules/node-dev/lib/hook.js:58:7)
at require.extensions.(anonymous function) (/Users/nburk/Developer/node/templates/react-universal-web-apps-simple/node_modules/babel-core/lib/api/register/node.js:214:7)
at Object.nodeDevHook [as .js] (/Users/nburk/Developer/node/templates/react-universal-web-apps-simple/node_modules/node-dev/lib/hook.js:58:7)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
[19:10:39] Finished 'build:watch:app' after 12 ms
[19:10:39] Starting 'lint:app'...
[ERROR] 19:10:39 TypeError
[19:10:39] Starting 'server'...
Does anyone see what I am missing? I have no clue where even to start, the filenames in the error don't really tell me anything...
Update
I checked for the file where the error occurs (/node_modules/node-dev/lib/hook.js), here's the code that causes it:
/**
* Patch the specified method to watch the file at the given argument
* index.
*/
function patch(obj, method, optionsArgIndex) {
var orig = obj[method];
if (!orig) return;
obj[method] = function () {
var opts = arguments[optionsArgIndex];
var file = typeof opts == 'string' ? opts : opts.filename;
if (file) callback(file);
return orig.apply(this, arguments);
};
}
You are getting that error because you are trying to access a property of a variable whose value is undefined. In your case, opts is getting the value undefined from var opts = arguments[optionsArgIndex]; this line and you cannot access a property of an undefined variable.
Wrap this up in try-catch or add checks before accessing nested properties of objects. It is generally considered a bad approach in JavaScript to access nested variables directly.
For example, instead of var a = b.c.d; you should use var a = (a && a.b && a.b.c) || <some default value>;
In the first case, if b or c is undefined, your app will crash, however, if b or c is undefined in the second case, a will be assigned the default value which you provided
You can solve this problem simply by explicitly force previous version of node-dev by doing this:
npm i node-dev#3.0.0 --save-dev
Fix#130 https://github.com/fgnass/node-dev/issues/130 brings some other mentioned by #rramakrishnaa bugs.