forked from codex-academy/ThinkingAboutFixing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 54905ab
Showing
17 changed files
with
1,311 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Debugging Tips | ||
|
||
A large part of a software developers job is to find problems. To find problems in existing applications and to minimize problems in applications. | ||
|
||
In this session we will look at tips, tricks and techniques for tracking down problems in our applications. | ||
|
||
## We will look at: | ||
* How to track down errors | ||
* Analyzing stack traces | ||
* Isolating an issue | ||
* Debugging tools | ||
|
||
## How to track down errors: | ||
* Understanding the big picture | ||
* What areas in the application are error prone | ||
* What clues do we have? | ||
* How to read error messages | ||
|
||
## Analyzing stack traces: | ||
* Which code is yours? | ||
* At which line is the error? | ||
* Why could things go wrong at that line? | ||
* Silent failure? | ||
|
||
## Isolating an issue: | ||
* Remove code - check if it still fails | ||
* Put code back until the error happens again | ||
* Look at lines before & after the problem | ||
|
||
## Debugging tools | ||
* Chrome developer tools - break points | ||
* print things to the console. | ||
* break problem down into components | ||
* use log files - with various log levels | ||
|
||
#Setup | ||
|
||
## Create a database | ||
|
||
```sql | ||
CREATE DATABASE debugging_tips; | ||
CREATE USER debugger@localhost IDENTIFIED BY 'password'; | ||
GRANT ALL PRIVILEGES ON debugging_tips.* TO debugger@localhost; | ||
FLUSH PRIVILEGES; | ||
``` | ||
|
||
## Create tables | ||
|
||
```sql | ||
create table issues ( | ||
id int not null auto_increment, | ||
heading char(100) not null, | ||
description text, | ||
primary key(id) | ||
); | ||
``` | ||
|
||
## Install the dependencies | ||
|
||
Using: `npm install` | ||
|
||
## Tools for break points | ||
|
||
[Node Inspector](https://github.com/node-inspector/node-inspector) | ||
|
||
[Using MS Visual Code](http://stackoverflow.com/questions/30023736/mocha-breakpoints-using-visual-studio-code) |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Errors | ||
====== | ||
* remove a callback from the module | ||
* using an undefined route | ||
* using an undefined method on a route that exists | ||
* invalid database credentials | ||
* can not get post | ||
* redirect invalid | ||
* unexpected token - no comma where there should be one | ||
* edit the text area for the edit | ||
* uninstall module |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use strict'; | ||
|
||
var express = require('express'), | ||
exphbs = require('express-handlebars'), | ||
mysql = require('mysql'), | ||
myConnection = require('express-myconnection'), | ||
bodyParser = require('body-parser'), | ||
issues = require('./issues'); | ||
|
||
var app = express(); | ||
|
||
var dbOptions = { | ||
host: 'localhost', | ||
user: 'debugger', | ||
password: 'passworddd', | ||
port: 3306, | ||
database: 'debugging_tips' | ||
}; | ||
|
||
//setup template handlebars as the template engine | ||
app.engine('handlebars', exphbs({defaultLayout: 'main'})); | ||
app.set('view engine', 'handlebars'); | ||
|
||
app.use(express.static(__dirname + '/public')); | ||
|
||
//setup middleware | ||
app.use(myConnection(mysql, dbOptions, 'single')); | ||
// parse application/x-www-form-urlencoded | ||
app.use(bodyParser.urlencoded({ extended: false })) | ||
// parse application/json | ||
app.use(bodyParser.json()) | ||
|
||
function errorHandler(err, req, res, next) { | ||
res.status(500); | ||
res.render('error', { error: err }); | ||
} | ||
|
||
//setup the handlers | ||
app.get('/', issues.all); | ||
app.get('/issues', issues.all); | ||
app.get('/issues/add' issues.showAdd); | ||
app.get('/issues/:id', issues.get); | ||
app.post('/issues/update/:id', issues.update); | ||
app.post('/issuesss', issues.add); | ||
app.get('/issues/delete/:id', issues.delete); | ||
|
||
//this should be a post but this is only an illustration of CRUD - not on good practices | ||
app.delete('/issues/:id', issues.delete); | ||
|
||
app.use(errorHandler); | ||
|
||
//configure the port number using and environment number | ||
var portNumber = process.env.CRUD_PORT_NR || 3000; | ||
|
||
//start everything up | ||
app.listen(portNumber, function () { | ||
console.log('Debugging Tips app running at port # :', portNumber); | ||
}); |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
var logger = require('./log'); | ||
|
||
exports.all = function (req, res) { | ||
req.getConnection(function(err, connection){ | ||
connection.query("select * from issues", function(err, results){ | ||
res.render('issues', {issues : results}) | ||
}); | ||
}); | ||
} | ||
|
||
exports.get = function (req, res) { | ||
req.getConnection(function(err, connection){ | ||
connection.query("select * from issues where id = ?", req.params.id, function(err, results){ | ||
console.log(results); | ||
return res.render('issue_edit', {issue : results[0]}) | ||
}); | ||
}); | ||
|
||
} | ||
|
||
exports.update = function (req, res) { | ||
req.getConnection(function(err, connection){ | ||
var data = { | ||
heading : req.body.heading, | ||
description : req.body.description | ||
}; | ||
|
||
connection.query("update issues set ? where id = ?", [data, req.params.id], function(err, results){ | ||
// what will happen here? | ||
return res.redirect("/issues"); | ||
}); | ||
}); | ||
} | ||
|
||
exports.showAdd = function (req, res) { | ||
res.render('isue') | ||
} | ||
|
||
exports.add = function (req, res) { | ||
|
||
var data = { | ||
heading : req.body.heading, | ||
description : req.body.description | ||
} | ||
req.getConnection(function(err, connection){ | ||
// what can I do better here? | ||
connection.query("insert into issues set ?", data, function(err, results){ | ||
// what can I do better here? | ||
res.redirect('/issues') | ||
}); | ||
}); | ||
} | ||
|
||
exports.delete = function (req, res, next) { | ||
req.getConnection(function(err, connection){ | ||
connection.query("delete from isues where id = ?", req.params.id, function(err, results){ | ||
//if (err) return next(err); | ||
res.redirect('/issues') | ||
}); | ||
}); | ||
|
||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var winston = require('winston'); | ||
|
||
winston.add(winston.transports.File, { filename: "./logs/logger.log" }); | ||
winston.info('Chill Winston, the logs are being captured...'); | ||
|
||
module.exports=winston; |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "debugging-tips", | ||
"version": "1.0.0", | ||
"description": "A large part of a software developers job is to find problems. To find problems in existing applications and to minimize problems in applications.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/codex-academy/DebuggingTips.git" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/codex-academy/DebuggingTips/issues" | ||
}, | ||
"homepage": "https://github.com/codex-academy/DebuggingTips#readme", | ||
"dependencies": { | ||
"body-parser": "^1.9.2", | ||
"express": "^4.10.2", | ||
"express-handlebars": "^1.1.0", | ||
"express-myconnection": "^1.0.4", | ||
"mysql": "^2.5.3", | ||
"winston": "^2.0.1" | ||
} | ||
} |
Binary file not shown.
Oops, something went wrong.