From 03a8d1e0fc32075ee2ccf5bf1e67c112ddd9b1b7 Mon Sep 17 00:00:00 2001 From: Kunal Kundu <51631122+tinfoil-knight@users.noreply.github.com> Date: Fri, 24 Sep 2021 21:15:07 +0530 Subject: [PATCH] fix: add back missing aws-sdk dep warning (#3384) * fix: add back missing aws-sdk dep warning * fix: preoprty of undefined error in detectAwsSdkError Co-authored-by: ehmicky --- src/lib/functions/synchronous.js | 4 ++++ src/lib/functions/utils.js | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib/functions/synchronous.js b/src/lib/functions/synchronous.js index 5ad5e240ff2..07fccbf83e6 100644 --- a/src/lib/functions/synchronous.js +++ b/src/lib/functions/synchronous.js @@ -2,6 +2,8 @@ const { Buffer } = require('buffer') const { NETLIFYDEVERR } = require('../../utils/logo') +const { detectAwsSdkError } = require('./utils') + const addHeaders = (headers, response) => { if (!headers) { return @@ -36,6 +38,8 @@ const handleSynchronousFunction = function (err, result, response) { const formatLambdaLocalError = (err) => `${err.errorType}: ${err.errorMessage}\n ${err.stackTrace.join('\n ')}` const handleErr = function (err, response) { + detectAwsSdkError({ err }) + response.statusCode = 500 const errorString = typeof err === 'string' ? err : formatLambdaLocalError(err) response.end(errorString) diff --git a/src/lib/functions/utils.js b/src/lib/functions/utils.js index c5e09d84f12..39d4e842372 100644 --- a/src/lib/functions/utils.js +++ b/src/lib/functions/utils.js @@ -1,5 +1,6 @@ const chalk = require('chalk') +const { warn } = require('../../utils/command-helpers') const { getLogMessage } = require('../log') const BASE_64_MIME_REGEXP = /image|audio|video|application\/pdf|application\/zip|applicaton\/octet-stream/i @@ -10,8 +11,8 @@ const DEFAULT_LAMBDA_OPTIONS = { const SECONDS_TO_MILLISECONDS = 1000 -const detectAwsSdkError = ({ error, warn }) => { - const isAwsSdkError = error.errorMessage && error.errorMessage.includes("Cannot find module 'aws-sdk'") +const detectAwsSdkError = ({ error }) => { + const isAwsSdkError = error && error.errorMessage && error.errorMessage.includes("Cannot find module 'aws-sdk'") if (isAwsSdkError) { warn(getLogMessage('functions.missingAwsSdk'))