Last active
April 3, 2021 15:04
-
-
Save ericpkatz/ead6bf849a51c7da3d7b51ca7c6fd365 to your computer and use it in GitHub Desktop.
Revisions
-
ericpkatz revised this gist
Apr 3, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,7 +38,7 @@ syncAndSeed() .then( ()=> { console.log('seeded');//BUG this still prints because of swallowed error }) .catch( ex => console.log(ex));//BUG there was an error but we don't catch it ``` - note in the ***createByName*** method I am swallowing the error. If you see code which catches an error, and does nothing with it, then it is swallowing the error. Usually not a good sign. -
ericpkatz revised this gist
Mar 31, 2021 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,14 +31,14 @@ const syncAndSeed = async()=> { }; ``` - demonstration of a bug is shown in the code below. ```javascript syncAndSeed() .then( ()=> { console.log('seeded');//BUG this still prints because of swallowed error }) .catch( ex => console.log(ex));//BUG there was an error ``` - note in the ***createByName*** method I am swallowing the error. If you see code which catches an error, and does nothing with it, then it is swallowing the error. Usually not a good sign. -
ericpkatz revised this gist
Mar 31, 2021 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ - a swallowed error in a Sequelize method will prevent an express route from detecting the error - both of these often result in difficult to detect bugs - I think this is a valid example with Sequelize. You can imagine the ***createByName*** method being called in an express route, but I'm just using it to seed the database. ```javascript const Sequelize = require('sequelize'); @@ -41,9 +41,9 @@ syncAndSeed() .catch( ex => console.log(ex)); ``` - note in the ***createByName*** method I am swallowing the error. If you see code which catches an error, and does nothing with it, then it is swallowing the error. Usually not a good sign. - the solution is to ***catch the error and throw it*** or to ***not catch it at all*** ```javascript User.createByName = async function(name){ -
ericpkatz revised this gist
Mar 31, 2021 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ - a swallowed error in a Sequelize method will prevent an express route from detecting the error - both of these often result in difficult to detect bugs - I think this is a valid example with Sequelize. You can imagine the **createByName** method being called in an express route, but I'm just using it to seed the database. ```javascript const Sequelize = require('sequelize'); @@ -29,7 +29,11 @@ const syncAndSeed = async()=> { await User.createByName('moe'); await User.createByName('larry');//this won't work, max 4 characters }; ``` - demonstration of the bug is shown in the code below. ``` syncAndSeed() .then( ()=> { console.log('seeded');//BUG this still prints because of swallowed error -
ericpkatz revised this gist
Mar 31, 2021 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ - a swallowed error in a thunk will prevent a component from detecting the error - a swallowed error in a Sequelize method will prevent an express route from detecting the error - both of these often result in difficult to detect bugs - I think this is a valid example with Sequelize. You can imagine the createByName method being called in an express route, but I'm just using it to seed the database. -
ericpkatz revised this gist
Mar 31, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,7 +38,7 @@ syncAndSeed() - note in the **createByName** method I am swallowing the error. If you see code which catches an error, and does nothing with it, then it is swallowing the error. Usually not a good sign. - the solution is to **catch the error and throw it** or to **not catch it at all** ```javascript User.createByName = async function(name){ -
ericpkatz revised this gist
Mar 31, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,7 +38,7 @@ syncAndSeed() - note in the **createByName** method I am swallowing the error. If you see code which catches an error, and does nothing with it, then it is swallowing the error. Usually not a good sign. - the solution is to **catch the error then throw it** or to **not catch it at all** ```javascript User.createByName = async function(name){ -
ericpkatz revised this gist
Mar 31, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,9 +36,9 @@ syncAndSeed() .catch( ex => console.log(ex)); ``` - note in the **createByName** method I am swallowing the error. If you see code which catches an error, and does nothing with it, then it is swallowing the error. Usually not a good sign. - the solution is to **not catch the error** if you are going to swallow it (no catch) or **catch it but then throw it** ```javascript User.createByName = async function(name){ -
ericpkatz revised this gist
Mar 31, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ # Issue - the "swallowing" of errors - a swallowed error in a thunk will prevent a component from detecting the error - a swallowed error in a Sequelize method will prevent an express route from detecting the error -
ericpkatz revised this gist
Mar 31, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ - a swallowed error in a thunk will prevent a component from detecting the error - a swallowed error in a Sequelize method will prevent an express route from detecting the error - I think this is a valid example with Sequelize. You can imagine the createByName method being called in an express route, but I'm just using it to seed the database. ```javascript const Sequelize = require('sequelize'); -
ericpkatz revised this gist
Mar 31, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ - there is something that I've seen in some of our workshops and solutions that I think are a bit problematic, which I wanted to address. - basically it's the "swallowing" of errors. I see the issue in Sequelize models and in thunks - a swallowed error in a thunk will prevent a component from detecting the error - a swallowed error in a Sequelize method will prevent an express route from detecting the error @@ -36,7 +36,7 @@ syncAndSeed() .catch( ex => console.log(ex)); ``` - note in the createByName method I am swallowing the error. If you see code which catches an error and doing nothing with it, then it is swallowing the error. Usually not a good sign. - the solution is to not catch the error if you are going to swallow it (no catch) or catch it but then throw it -
ericpkatz revised this gist
Mar 31, 2021 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ - a swallowed error in a thunk will prevent a component from detecting the error - a swallowed error in a Sequelize method will prevent an express route from detecting the error - I think this is a valid example ```javascript const Sequelize = require('sequelize'); @@ -26,12 +26,12 @@ User.createByName = async function(name){ const syncAndSeed = async()=> { await conn.sync({ force: true }); await User.createByName('moe'); await User.createByName('larry');//this won't work, max 4 characters }; syncAndSeed() .then( ()=> { console.log('seeded');//BUG this still prints because of swallowed error }) .catch( ex => console.log(ex)); ``` -
ericpkatz created this gist
Mar 31, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ - there is something that I've seen in some of our workshops and solutions that I think are a bit problematic which I wanted to address. - basically it's the "swallowing" of errors. I see the issue in Sequelize models and in thunks - a swallowed error in a thunk will prevent a component from detecting the error - a swallowed error in a Sequelize method will prevent an express route from detecting the error - I think this is an example ```javascript const Sequelize = require('sequelize'); const { DataTypes: { STRING } } = Sequelize; const conn = new Sequelize(process.env.DATABASE_URL || 'postgres://localhost/acme_db'); const User = conn.define('user', { name: STRING(4) }); User.createByName = async function(name){ try { return await this.create({ name }); } catch(ex){ console.log(ex); } }; const syncAndSeed = async()=> { await conn.sync({ force: true }); await User.createByName('moe'); await User.createByName('larry'); }; syncAndSeed() .then( ()=> { console.log('seeded'); }) .catch( ex => console.log(ex)); ``` - note in the createByName method I am swallowing the error, if you see code which catches an error and doing nothing with it, then it is swallowing the error. - the solution is to not catch the error if you are going to swallow it (no catch) or catch it but then throw it ```javascript User.createByName = async function(name){ try { return await this.create({ name }); } catch(ex){ console.log(ex); throw ex; } }; ``` or even better ```javascript User.createByName = function(name){ return this.create({ name }); }; ```