From 15e5a31767b177cf2e48e16723a7dc268f8508da Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Mon, 9 Jan 2023 14:53:35 -0500 Subject: [PATCH] If no stub exists, start stub as {}, not undefined Recent changes to handle bad brew properties (tags as strings, no renderer, etc.) didn't account for the case where an old Google brew is first being stubbed; since no stub exists, there is no object to perform the corrections on, and we crash. --- server/homebrew.api.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 18269a639..b4339011f 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -47,7 +47,7 @@ const api = { console.warn(err); } }); - stub = stub?.toObject(); + stub = stub?.toObject() || {}; // If there is a google id, try to find the google brew if(!stubOnly && (googleId || stub?.googleId)) { @@ -77,8 +77,8 @@ If you believe you should have access to this brew, ask the file owner to invite } // Clean up brew: fill in missing fields with defaults / fix old invalid values - stub.tags = stub?.tags || undefined; // Clear empty strings - stub.renderer = stub?.renderer || undefined; // Clear empty strings + stub.tags = stub.tags || undefined; // Clear empty strings + stub.renderer = stub.renderer || undefined; // Clear empty strings stub = _.defaults(stub, DEFAULT_BREW_LOAD); // Fill in blank fields req.brew = stub;