Skip to content

Instantly share code, notes, and snippets.

Error handling antipattern

So I trace down a 500 to the line:

foo.get_bar(bar)

which is raising an IndexError. I figure out it means that there is no such bar, and that in that case we want to do nothing, so I change it to

@dannyroberts
dannyroberts / subtree-merge
Last active August 29, 2015 14:04
Example subtree merge
git remote add -f couchforms git://github.com/dimagi/couchforms.git
git merge -s ours --no-commit couchforms/master
# --prefix lets you specify where to put the submodule code
# the thing after the colon in couchforms/master:couchforms
# lets you specify what part of the submodule code to merge in
git read-tree --prefix=corehq/ex-submodules/couchforms -u couchforms/master:couchforms
git commit -m "subtree merge couchforms into corehq/ex-submodules"
@dannyroberts
dannyroberts / backwards-migration-staging.md
Last active August 29, 2015 14:17
Backwargs migrations on staging

I started out trying to do something simple, remove the tf-perisistence branch of touchforms from staging.yml.

Things went well until I got this error

[hqdb0-staging.internal.commcarehq.org] sudo: /home/cchq/www/staging/python_env/bin/python manage.py migrate --noinput
[hqdb0-staging.internal.commcarehq.org] out: 2015-03-19 18:02:01,478 INFO Raven is not configured (disabled). Please see documentation for more information.
[hqdb0-staging.internal.commcarehq.org] out: GhostMigrations: 
[hqdb0-staging.internal.commcarehq.org] out: 
[hqdb0-staging.internal.commcarehq.org] out:  ! These migrations are in the database but not on disk:

Forward Forms

FORM/POST PARAMETERS

None

QUERYSTRING
app_id: db9f874f0219444ee7848ddd023e292e
/* copied from http://www.netlobo.com/url_query_string_javascript.html */
function get_url_param( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
@dannyroberts
dannyroberts / update-code.sh
Last active December 12, 2015 09:19
bash function to fetch the latest master on all submodules in parallel, wait until they're all updated, and then delete all pyc files
function delete-pyc() {
find . -name '*.pyc' -delete
}
function pull-latest-master() {
git checkout master; git pull &
git submodule foreach --recursive 'git checkout master; git pull &'
until [ -z "$(ps aux | grep '[g]it pull')" ]; do sleep 1; done
}
function update-code() {
pull-latest-master
alias branch="git branch | grep '^\*' | sed 's/* //'"
alias push-current='git push origin $(branch)'
function delete-pyc() {
find . -name '*.pyc' -delete
}
function pull-latest-master() {
git checkout master; git pull origin master
git submodule update --init
git submodule foreach --recursive 'git checkout master; git pull origin master &'
until [ -z "$(ps aux | grep '[g]it pull')" ]; do sleep 1; done
}
function update-code() {
@dannyroberts
dannyroberts / git-aliases.sh
Last active December 16, 2015 20:10
My git-related shortcuts
source /usr/local/git/contrib/completion/git-completion.bash
alias g="git"; __git_complete g _git
alias l="git status"
alias d="git diff"; __git_complete d _git_diff
alias ds="git diff --cached"
alias m="git commit -m "
alias am="git commit -am "
alias a="git add "
alias o-="git checkout --"
alias o="git checkout"; __git_complete o _git_checkout
"""
This file is meant to be used in the following manner:
$ python make_rebuild_staging.py < staging.yaml > rebuildstaging-tmp.sh; bash rebuildstaging-tmp.sh
Where staging.yaml looks as follows:
trunk: master
name: autostaging
branches: