Open Side Menu Go to the Top
Register
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

10-09-2018 , 09:15 PM
Yeah but you already have to execute the callback, handle the error, and return (resolve) the value. The promise wrapper is verbosity for no purpose there.

I would also be curious if just this works:
Code:
const util = require('util');

module.exports.firstRun = (event, context) => {
  return util.promisify(docClient.scan)(params);
};
works with fs, returns a promise of the result. Dope
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-09-2018 , 11:44 PM
Sure promisify would probably work. It's just turning the callback into a promise. (I'll check at work tomorrow). But with every extra external package you load with lambda it slows things down a bit as far as deploy. I try to avoid them.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 03:00 AM
Util is native, it literally is doing what you are doing inside of its impl, not sure what is happening here lol


@Goofy, you use any libs for testing in Go? As a ruby/js shop, people were talking about ginkgo, but do any gophers actually use that? testify and the standard lib feels so manual to me, but that seems to usually be the go way
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 01:22 PM
This works. Pretty cool. Only tricky part is apparently dynamo docClient.scan is using this somewhere - so I had to bind it.

Code:
const docClient = new AWS.DynamoDB.DocumentClient();
const {promisify} = require('util');

module.exports.firstRun = (event, context) => {
  return promisify(docClient.scan).bind(docClient)(params);
};

module.exports.findGeocode = (event, context) => {
  const address = `${event.line1}, ${event.city}, ${event.zipCode}`;

  return promisify(googleApiClient.geocode)({address});
};
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 05:11 PM
I have discovered that I actually like try/catch - as long as someone else's code has to do the catching. In this case the AWS framework that's invoking the lambda:

Code:
module.exports.findGeocode = async (event, context) => {
  const address = `${event.line1}, ${event.city}, ${event.zipCode}`;

  const geocode = (await promisify(googleApiClient.geocode)({address})).json.results[0];

  return (geocode) ? geocode.geometry.location : {msg:'no locations found'};
};
No location found is handled. Any other more severe error is just thrown up to whatever is calling findGeocode. Not my problem - you deal with it.

I guess this could work as long as you design your code around throwing and catching errors, instead of gracefully handling callback(err, response) up and down the line.

Last edited by suzzer99; 10-10-2018 at 05:17 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 05:58 PM
Man I am literally going to have to get rid of Sublime for one and one reason - lack of a good JS linter option. JSHint and ESLint both work, usually after a few hours of hair-pulling. But they both have really ****ty default settings - like ES5 - and to override those you have to import a .jshintrc or .eslintrc into EACH PROJECT. That's just to get stuff like ES6 - and who wants that crazy ****?

With lambda and serverless.com - I'm constantly creating tons of little projects. Always having to import those files into it is really annoying.

How is it that every other IDE on earth just works out of the box with good linting - and Sublime Text is an absolute nightmare?

One of the things I don't like about the other IDEs is it's usually really hard to have multiple folders/projects open at once.

Also I want to allow files in view to update if they're changed behind the scenes, but still be able to Ctrl-Z to go back if I don't like the update. This has saved my ass on git merge problems many times.

And find across files is usually terrible in other IDEs. Argh. I know the other IDEs have a lot more full-featured stuff. But right now I'm really just POCing a million different little things. So it's not worth it to me to have to learn all the heavy-duty dev tools.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 06:41 PM
I have now gone down the biggest rabbit hole since I started my new job just trying to get eslint to work and not complain about this:

Code:
module.exports.firstRun =  async (event, context) => {
It doesn't like the arrow function in the async method for some reason. eslint discussion on the internet is destroying my brain. They're all extending airbnb or some other random **** and I have no idea what's going on.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 07:10 PM
Well I got it working with the options below:

Code:
{
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "experimentalObjectRestSpread": true
    },
  },

  "env": {
    "es6": true,
    "node": true
  },
  
  "extends": "eslint:recommended",

  "rules": {
    "no-unused-vars": ["warn", { "vars": "all", "args": "none", "ignoreRestSiblings": false }],
    "no-console": 0,
  }
}
But if I try to remove either the experimentalObjectRestSpread entry or the "extends" line - it breaks again.

And not just like "I don't like this arrow function". The parser crashes and stops when it sees that. Not super confidence-instilling.

And I'm still back to my original problem in that I have to have this stupid .eslintrc file in every project.

EDIT: OMFG - all I have to do is put the .eslintrc file in the parent directory that I put all my projects in. Why don't they just tell you that?!Q@?Q!#??@!#? 2 hours of ****ing googling and no one says that ever.

Look at all this bull**** to create a "sharable config" and you still have to freaking set it up in each project.

Last edited by suzzer99; 10-10-2018 at 07:18 PM. Reason: HYATCHYATCHYATCHAHAHAHAHQA
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 07:12 PM
Looks like we need a separate JS thread.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 07:27 PM
Quote:
Originally Posted by PJo336
@Goofy, you use any libs for testing in Go? As a ruby/js shop, people were talking about ginkgo, but do any gophers actually use that? testify and the standard lib feels so manual to me, but that seems to usually be the go way
We use testify.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 07:41 PM
Quote:
Originally Posted by :::grimReaper:::
Looks like we need a separate JS thread.


Lol
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 07:46 PM
Quote:
Originally Posted by suzzer99
I have now gone down the biggest rabbit hole since I started my new job just trying to get eslint to work and not complain about this:

Code:
module.exports.firstRun =  async (event, context) => {
It doesn't like the arrow function in the async method for some reason. eslint discussion on the internet is destroying my brain. They're all extending airbnb or some other random **** and I have no idea what's going on.
Word to the wise: you should never export arrow functions. If you are exporting arrow functions then you clearly don't understand what they are meant to be used for
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 08:12 PM
Take it up with AWS, I'm just following their pattern for lambda handlers: https://aws.amazon.com/blogs/compute...in-aws-lambda/

Code:
let AWS = require('aws-sdk');
let lambda = new AWS.Lambda();
let data;

exports.handler = async (event) => {
    try {
        data = await lambda.getAccountSettings().promise();
    }
    catch (err) {
        console.log(err);
        return err;
    }
    return data;
};
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 08:54 PM
I'm all for using ES6. What I am not for is blindly using it in inappropriate spots. Blindly using arrow functions everywhere in every situation is absolutely inappropriate imo.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 09:25 PM
Suzzer why don't you use vs vscode?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 09:33 PM
Quote:
Originally Posted by Craggoo
I'm all for using ES6. What I am not for is blindly using it in inappropriate spots. Blindly using arrow functions everywhere in every situation is absolutely inappropriate imo.
Do you want to elaborate here? In your opinion, when should you use arrow functions, when should you not and why?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 10:35 PM
Quote:
Originally Posted by candybar
Do you want to elaborate here? In your opinion, when should you use arrow functions, when should you not and why?
Arrow functions "inherit" context without you having to pass it through via bind. What does this mean? This means several things:

1) If you plan on passing in a this value when you call a function, the function should not be an arrow function because the context you pass in will be ignored.
2) In the AWS example, the context will be undefined therefore rendering an arrow function in that example really pointless

The only time where you should use arrow functions is when you want to reference the enclosing context without having to do the
Code:
var that = this;
little trick.

I would generally argue against using arrow functions entirely. Imagine a scenario where you have a bunch of nested arrow functions. You would need to track down which context is actually being used (implicit) instead of explicitly binding the context you want (explicit).
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 11:08 PM
Javascript is such a blight
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-10-2018 , 11:11 PM
The better solution is to not use this.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2018 , 12:04 AM
Quote:
Originally Posted by Victor
Suzzer why don't you use vs vscode?
Not being able to open multiple folders/projects at once in the same window really harshes my buzz.

If all I was doing was heavy duty development on one or two projects I would probably use VS code or Atom or something and get into debuggers and all that. But I'm doing a million little POCs in all kinds of different languages and stuff. So I just want to be nimble.

The AWS SDK for VS Code, which is awesome, only works on PC unfortunately.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2018 , 12:34 AM
Quote:
Originally Posted by Larry Legend
The better solution is to not use this.
ding ding ding
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2018 , 06:00 AM
Quote:
Originally Posted by suzzer99
Not being able to open multiple folders/projects at once in the same window really harshes my buzz.

If all I was doing was heavy duty development on one or two projects I would probably use VS code or Atom or something and get into debuggers and all that. But I'm doing a million little POCs in all kinds of different languages and stuff. So I just want to be nimble.

The AWS SDK for VS Code, which is awesome, only works on PC unfortunately.
you can open as many folders (and run/build them concurrently) as you want with a Workspace in vsCode.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2018 , 07:19 AM
I have a cheap computer and Atom choked the hell out of it, so I went back to Vim.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2018 , 07:30 AM
Atom is just hopelessly bad.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2018 , 01:26 PM
Does anyone have glasses specifically for computer use?

I'm mildly/moderately near-sighted and have been since my 20s. I can get by at distance sorta, but really need glasses or contacts to drive. And now that I'm getting old, I can read fine w/o glasses or contacts, but if I am wearing my contacts I need reading glasses. But...nothing really works at the intermediate distance of a computer screen. I need to either get too close w/o contacts or too far with them.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote

      
m