fix bug in truncate function
better error reporting