Created
May 1, 2015 21:23
-
-
Save AndrewRayCode/03cf7f7aad087bf33aa5 to your computer and use it in GitHub Desktop.
Sane knex errors
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 characters
}).catch(function( error ) { | |
var errorPosition = Number(error.position), | |
msg = error.toString(), | |
query = msg.replace(/^.+: | - .+?$/g, ''), | |
sqlMsg = msg.replace(/^.+ - /g, ''), | |
context = 50, | |
leftTruncate = Math.max( errorPosition - context, 0 ); | |
console.error( query + ';' ); | |
console.error( error.severity + ': ' + sqlMsg ); | |
console.error( | |
( leftTruncate ? '…' : '' ) + | |
query.substring( | |
Math.max( errorPosition - context, 0 ), | |
Math.max( errorPosition + context ) | |
) + | |
( errorPosition + context < query.length ? '…' : '' ) | |
); | |
console.error( new Array( errorPosition - leftTruncate + !!leftTruncate ).join(' ') + '^' ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment