Skip to content

Instantly share code, notes, and snippets.

@dantleech
Created April 10, 2013 15:05
Show Gist options
  • Select an option

  • Save dantleech/5355412 to your computer and use it in GitHub Desktop.

Select an option

Save dantleech/5355412 to your computer and use it in GitHub Desktop.
Exception message reformatting script
#!/bin/bash
FILES=`find ./src/Symfony -name "*.php"`
OPTS=-i.bak
git reset --hard
# Fix 'This is '.$an.' exception '.$ok.' foo '.$bar
perl $OPTS -pe "s/throw new (.*)Exception\('(.*?)'\.(.*?)\.'(.*?)'\.(.*?)\.'(.*?)'\.([^']*?)\);/throw new \1Exception\(sprintf\('\2%s\4%s\6%s', \3, \5, \7\)\);/g" $FILES
# Fix 'This is '.$an.' exception '.$ok
perl $OPTS -pe "s/throw new (.*)Exception\('(.*?)'\.(.*?)\.'(.*?)'\.([^']*?)\);/throw new \1Exception\(sprintf\('\2%s\4%s', \3, \5\)\);/g" $FILES
# Fix 'This is '.$an.' foo'
perl $OPTS -pe "s/throw new (.*)Exception\('(.*?)'\.(.*?)\.'(.*?)'\);/throw new \1Exception\(sprintf\('\2%s\4', \3\)\);/g" $FILES.' foo'
# Fix 'This is '.$an
perl $OPTS -pe "s/throw new (.*)Exception\('(.*?)'\.([^']*?)\);/throw new \1Exception\(sprintf\('\2%s', \3\)\);/g" $FILES
rm `find ./src/Symfony -name "*.bak"`
grep -Rn 'throw new ' | grep -v "sprintf" | grep "'\." | wc -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment